fix json tool (#9096)

pull/9104/head
Bagatur 1 year ago committed by GitHub
parent 2184e3a400
commit 3ab4e21579
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -20,7 +20,7 @@ def _parse_input(text: str) -> List[Union[str, int]]:
"""Parse input of the form data["key1"][0]["key2"] into a list of keys."""
_res = re.findall(r"\[.*?]", text)
# strip the brackets and quotes, convert to int if possible
res = [i[1:-1].replace('"', "") for i in _res]
res = [i[1:-1].replace('"', "").replace("'", "") for i in _res]
res = [int(i) if i.isdigit() else i for i in res]
return res

@ -30,6 +30,10 @@ def test_json_spec_value() -> None:
assert spec.value('data["baz"]') == "{'test': {'foo': [1, 2, 3]}}"
assert spec.value('data["baz"]["test"]') == "{'foo': [1, 2, 3]}"
assert spec.value('data["baz"]["test"]["foo"]') == "[1, 2, 3]"
assert spec.value("data['foo']") == "bar"
assert spec.value("data['baz']") == "{'test': {'foo': [1, 2, 3]}}"
assert spec.value("data['baz']['test']") == "{'foo': [1, 2, 3]}"
assert spec.value("data['baz']['test']['foo']") == "[1, 2, 3]"
def test_json_spec_value_max_length() -> None:

Loading…
Cancel
Save