string(JSON ... GET ...) should return strings in json encoding
actual:
json SET
takes json-encoded strings
json GET
returns raw strings
expected:
json GET
and SET
should be consistent,
both should take/return json-encoded strings
why:
this makes it easier to copy data between json documents
related issue #23750 (add SET_STRING
subcommand)
to avoid breaking the API, we could keep GET
as is,
and add a flag like RETURN_JSON_STRINGS
to json GET
set(json_str [[ {"a": {"b": ["c"]}} ]])
string(JSON value GET "${json_str}" a)
message("value = ${value}") # {"b": ["c"]}
string(JSON value GET "${json_str}" a b)
message("value = ${value}") # ["c"]
string(JSON value GET "${json_str}" a b 0)
message("value = ${value}") # c # expected: "c"
#string(JSON json_str SET "${json_str}" a b 1 "d") # Syntax error: value, object or array expected.
string(JSON json_str SET "${json_str}" a b 1 "\"d\"")
message("json_str = ${json_str}") # {"a": {"b": ["c", "d"]}}