tidwall / gjson

Get JSON values quickly - JSON parser for Go
MIT License
13.95k stars 841 forks source link

Queries for keys that have special characters are not fully supported #270

Open volans- opened 2 years ago

volans- commented 2 years ago

Given the following JSON:

[
    {"a!=e": 10},
    {"a!=e": 20}
]

It seems to not be possible to query for say all items with the value of "a!=e" greater than 15. Things I've tried:

The workaround I found is to use wildcards (#(a??e>15)#), but wildcards might not allow to solve all possible scenarios. If this is an intended limitation maybe it should be mentioned in the readme/syntax page.

tidwall commented 2 years ago

It probably should be documented, but you need to escape the path.

#(a\!\=e>15)# -> [{"a!=e": 20}]
volans- commented 2 years ago

@tidwall Got it, thanks for the explanation. I was also surprised that escaping other characters has no effects. For example #(\a\!\=e>15)# does work too.

lammel commented 2 years ago

It probably should be documented, but you need to escape the path.

#(a\!\=e>15)# -> [{"a!=e": 20}]

Actually it is documented in (SYNTAX.md). Maybe a short note on escaping should be added to the README.md too

volans- commented 2 years ago

@lammel thanks, I had actually read the paragraph of the documentation that you linked above, but because it's right underneath the Wildcards section and it mentions the same specific characters, I had interpreted it as referring exclusively to those three characters. But I see now that reading it in isolation it can also be read as a more generic escaping method.

Maybe making that a bit more explicit in the docs could avoid any misinterpretation.