tfm.hyperparams.nested_csv_str_to_json_str

Converts a nested (using '.') comma-separated k=v string to a JSON string.

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} } }"

csv_str the comma separated string.

the converted JSON string.

ValueError If csv_str is not in a comma separated string or if the string is formatted incorrectly.