wanglingsong / JsonSurfer

A streaming JsonPath processor in Java
MIT License
292 stars 55 forks source link

Not working if node key is a number #31

Closed brolinuk closed 6 years ago

brolinuk commented 6 years ago

It looks like the path could not be parsed if the node key is a number, such as "$.tree.taxonomy.100177". Is there a dedicated expression that used for this case to work?

wanglingsong commented 6 years ago

Maybe $.tree.taxonomy.['100177']

brolinuk commented 6 years ago

nope, this doesn't work

objc[48631]: Class JavaLaunchHelper is implemented in both /Library/Java/JavaVirtualMachines/jdk1.8.0_65.jdk/Contents/Home/bin/java and /Library/Java/JavaVirtualMachines/jdk1.8.0_65.jdk/Contents/Home/jre/lib/libinstrument.dylib. One of the two will be used. Which one is undefined. Exception in thread "main" org.antlr.v4.runtime.misc.ParseCancellationException at org.antlr.v4.runtime.BailErrorStrategy.recoverInline(BailErrorStrategy.java:66) at org.antlr.v4.runtime.Parser.match(Parser.java:206) at org.jsfr.json.compiler.JsonPathParser.childNode(JsonPathParser.java:647) at org.jsfr.json.compiler.JsonPathParser.relativePath(JsonPathParser.java:254) at org.jsfr.json.compiler.JsonPathParser.path(JsonPathParser.java:134) at org.jsfr.json.compiler.JsonPathCompiler.compile(JsonPathCompiler.java:233) at org.jsfr.json.SurfingConfiguration$Builder.bind(SurfingConfiguration.java:131) at com.waitrose.spike.json.JsonSurfDemo.surfParse(JsonSurfDemo.java:75) at com.waitrose.spike.json.JsonSurfDemo.main(JsonSurfDemo.java:120) Caused by: org.antlr.v4.runtime.InputMismatchException at org.antlr.v4.runtime.BailErrorStrategy.recoverInline(BailErrorStrategy.java:61) ... 8 more

wanglingsong commented 6 years ago

@brolinuk Can you provide a sample json?

wanglingsong commented 6 years ago

$.tree.taxonomy['100177'] This one should work.

brolinuk commented 6 years ago

This seems working. Thanks.

Does it mean it has to use bracket–notation when the key is a number? I wasn't aware that the combination of bracket-notation and dot-notation can be used.

wanglingsong commented 6 years ago

Yes. bracket-notation has to be used to prevent the ambiguous of numeric key.