jmespath / jmespath.js

Javascript implementation of JMESPath, a query language for JSON
http://jmespath.org
Other
776 stars 95 forks source link

Special characters in keys not working #53

Closed laggingreflex closed 4 years ago

laggingreflex commented 4 years ago

Special characters in keys don't work

If I have data like this:

{ 'foo-bar': 'baz' }

And I use the search: 'foo-bar', it gives error.

> jmespath.search({ 'foo-bar': 'baz' }, 'foo-bar')
Thrown:
{ ParserError: Unexpected token type: Number, value: NaN
    at Parser.parse (…\node_modules\jmespath\jmespath.js:502:27)
    at Object.search (…\node_modules\jmespath\jmespath.js:1660:25) name: 'ParserError' }

Lots of other special characters don't seem to work either: .,/\|{}

Tested on v0.15.0

glenveegee commented 4 years ago

Also $ as in

{"$foo": "bar"}

jdthorpe commented 4 years ago

This version of jmespath doesn't have that particular problem: yarn add jmespath@0.14.0

glenveegee commented 4 years ago

Actually it turns out that the spec dictates that when special characters in keys occur the key should be quoted

So in the example above...

{"$foo": "bar"}

should be

jmespath.search({ 'foo-bar': 'baz' }, '"foo-bar"')

laggingreflex commented 4 years ago

Actually it turns out that the spec dictates that when special characters in keys occur the key should be quoted

jmespath.search({ 'foo-bar': 'baz' }, '"foo-bar"')

Ahh! That's superb. It works. Thanks! 👍