tfm.hyperparams.nested_csv_str_to_json_str
Stay organized with collections
Save and categorize content based on your preferences.
Converts a nested (using '.') comma-separated k=v string to a JSON string.
tfm.hyperparams.nested_csv_str_to_json_str(
csv_str
)
Converts a comma-separated string of key/value pairs that supports
nesting of keys to a JSON string. Nesting is implemented using
'.' between levels for a given key.
Spacing between commas and = is supported (e.g. there is no difference between
"a=1,b=2", "a = 1, b = 2", or "a=1, b=2") but there should be no spaces before
keys or after values (e.g. " a=1,b=2" and "a=1,b=2 " are not supported).
Note that this will only support values supported by CSV, meaning
values such as nested lists (e.g. "a=[[1,2,3],[4,5,6]]") are not
supported. Strings are supported as well, e.g. "a='hello'".
An example conversion would be:
"a=1, b=2, c.a=2, c.b=3, d.a.a=5"
to
"{ a: 1, b : 2, c: {a : 2, b : 3}, d: {a: {a : 5} } }"
Args |
csv_str
|
the comma separated string.
|
Returns |
the converted JSON string.
|
Raises |
ValueError
|
If csv_str is not in a comma separated string or
if the string is formatted incorrectly.
|
Except as otherwise noted, the content of this page is licensed under the Creative Commons Attribution 4.0 License, and code samples are licensed under the Apache 2.0 License. For details, see the Google Developers Site Policies. Java is a registered trademark of Oracle and/or its affiliates. Some content is licensed under the numpy license.
Last updated 2024-02-02 UTC.
[[["Easy to understand","easyToUnderstand","thumb-up"],["Solved my problem","solvedMyProblem","thumb-up"],["Other","otherUp","thumb-up"]],[["Missing the information I need","missingTheInformationINeed","thumb-down"],["Too complicated / too many steps","tooComplicatedTooManySteps","thumb-down"],["Out of date","outOfDate","thumb-down"],["Samples / code issue","samplesCodeIssue","thumb-down"],["Other","otherDown","thumb-down"]],["Last updated 2024-02-02 UTC."],[],[],null,["# tfm.hyperparams.nested_csv_str_to_json_str\n\n\u003cbr /\u003e\n\n|-----------------------------------------------------------------------------------------------------------------------------------|\n| [View source on GitHub](https://github.com/tensorflow/models/blob/v2.15.0/official/modeling/hyperparams/params_dict.py#L352-L452) |\n\nConverts a nested (using '.') comma-separated k=v string to a JSON string.\n\n#### View aliases\n\n\n**Main aliases**\n\n[`tfm.hyperparams.params_dict.nested_csv_str_to_json_str`](https://www.tensorflow.org/api_docs/python/tfm/hyperparams/nested_csv_str_to_json_str)\n\n\u003cbr /\u003e\n\n tfm.hyperparams.nested_csv_str_to_json_str(\n csv_str\n )\n\nConverts a comma-separated string of key/value pairs that supports\nnesting of keys to a JSON string. Nesting is implemented using\n'.' between levels for a given key.\n\nSpacing between commas and = is supported (e.g. there is no difference between\n\"a=1,b=2\", \"a = 1, b = 2\", or \"a=1, b=2\") but there should be no spaces before\nkeys or after values (e.g. \" a=1,b=2\" and \"a=1,b=2 \" are not supported).\n\nNote that this will only support values supported by CSV, meaning\nvalues such as nested lists (e.g. \"a=\\[\\[1,2,3\\],\\[4,5,6\\]\\]\") are not\nsupported. Strings are supported as well, e.g. \"a='hello'\".\n\nAn example conversion would be:\n\n\"a=1, b=2, c.a=2, c.b=3, d.a.a=5\"\n\nto\n\n\"{ a: 1, b : 2, c: {a : 2, b : 3}, d: {a: {a : 5} } }\"\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n| Args ---- ||\n|-----------|-----------------------------|\n| `csv_str` | the comma separated string. |\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n| Returns ------- ||\n|---|---|\n| the converted JSON string. ||\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n| Raises ------ ||\n|--------------|------------------------------------------------------------------------------------------|\n| `ValueError` | If csv_str is not in a comma separated string or if the string is formatted incorrectly. |\n\n\u003cbr /\u003e"]]