Closed sm-ffm closed 3 months ago
I've got the following Error - maybe a bug?:
jsonpath_ng.exceptions.JsonPathParserError: Parse error at 1:2 near token 1 (NUMBER)
I tried a lot, and it only raises, when Objectag only contains Numbers. I tried it with parsing / finding Data and Editing Data. Both raises Error.
Example Code:
import json from jsonpath_ng import jsonpath, parse def jsonparser(Path, Json): json_data = json.loads(Json) jsonpath_expression = parse(Path) Output = jsonpath_expression.find(json_data)[0].value return Output def jsonEditvalue(Path, Json, Value): json_data = json.loads(Json) jsonpath_expr = parse(Path) jsonpath_expr.find(json_data) jsonpath_expr.update(json_data, Value) Output = json.dumps(json_data, indent=2) return Output jsonstring = """ { "1" : { "One" : "Data1", "Two" : "Data2", "Three" : "Data3" }, "2" : { "One" : "Data1", "Two" : "Data2", "Three" : "Data3" } } """ print(jsonparser("$.1.One", jsonstring)) print(jsonEditvalue("$.1.One", jsonstring, "DataNew"))
jsonpath-ng is the first Parser I used with that Kind of Issue.
If you want to use keys that are only numbers, you should quote them
print(jsonparser("$.\"1\".One", jsonstring)) print(jsonEditvalue("$.\"1\".One", jsonstring, "DataNew"))
I've got the following Error - maybe a bug?:
I tried a lot, and it only raises, when Objectag only contains Numbers. I tried it with parsing / finding Data and Editing Data. Both raises Error.
Example Code:
jsonpath-ng is the first Parser I used with that Kind of Issue.