h2non / jsonpath-ng

Finally, a JSONPath implementation for Python that aims to be standard compliant. That's all. Enjoy!
Apache License 2.0
572 stars 85 forks source link

Parser failed to understand syntax '$.anykey.~'. error message: Parse error at 1:12 near token ~ (~) #117

Open madnanshah opened 1 year ago

madnanshah commented 1 year ago

{ "mainkey": { "k1": {}, "k2": {} } }

From above, when I try to get keys with $.mainkey.*~ I expect ["k1","k2"] but I get following error

Parser failed to understand syntax '$.mainkey.~'. error message: Parse error at 1:12 near token ~ (~)

Result of pip install --upgrade jsonpath-ng

Requirement already satisfied: jsonpath-ng in /usr/local/lib/python3.10/dist-packages (1.5.3) Requirement already satisfied: six in /usr/lib/python3/dist-packages (from jsonpath-ng) (1.16.0) Requirement already satisfied: ply in /usr/local/lib/python3.10/dist-packages (from jsonpath-ng) (3.11) Requirement already satisfied: decorator in /usr/local/lib/python3.10/dist-packages (from jsonpath-ng) (5.1.1)

GalexyN commented 1 year ago

I think would could use something like this instead

obj = { "mainkey": { "k1": {}, "k2": {} } }
print(parse("$.mainkey").find(obj)[0].value.keys())

Does jsonpath-ng support tilde? I've only seen it used with =~ for regex filtering I believe

AndreyMZ commented 8 months ago

Duplicates https://github.com/h2non/jsonpath-ng/issues/32.