JsonSurfer
JsonSurfer copied to clipboard
Results do not match other implementations
The following queries provide results that do not match those of other implementations of JSONPath (compare https://cburgmer.github.io/json-path-comparison/):
-
[x]
$.2
Input:{"a": "first", "2": "second", "b": "third"}
Expected output:
["second"]
Error:
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:672) at org.jsfr.json.compiler.JsonPathParser.relativePath(JsonPathParser.java:272) at org.jsfr.json.compiler.JsonPathParser.path(JsonPathParser.java:159) at org.jsfr.json.compiler.JsonPathCompiler.compile(JsonPathCompiler.java:283) at org.jsfr.json.compiler.JsonPathCompiler.compile(JsonPathCompiler.java:273) at org.jsfr.json.JsonSurfer.collectAll(JsonSurfer.java:262) at query.App.main(App.java:27) Caused by: org.antlr.v4.runtime.InputMismatchException at org.antlr.v4.runtime.BailErrorStrategy.recoverInline(BailErrorStrategy.java:61) ... 8 more
-
[ ]
$[-1]
Input:["first", "second", "third"]
Expected output:
["third"]
Actual output:
[]
-
[ ]
$[-1:]
Input:["first", "second", "third"]
Expected output:
["third"]
Actual output:
["first", "second", "third"]
-
[x]
$[?(@.key=="some.value")]
Input:[{"key": "some"}, {"key": "value"}, {"key": "some.value"}]
Expected output:
[{"key": "some.value"}]
Error:
line 1:11 token recognition error at: '"' line 1:22 token recognition error at: '"' line 1:12 no viable alternative at input '@.key==some' Exception in thread "main" org.antlr.v4.runtime.misc.ParseCancellationException at org.antlr.v4.runtime.BailErrorStrategy.recover(BailErrorStrategy.java:51) at org.jsfr.json.compiler.JsonPathParser.filterExpr(JsonPathParser.java:947) at org.jsfr.json.compiler.JsonPathParser.filter(JsonPathParser.java:768) at org.jsfr.json.compiler.JsonPathParser.relativePath(JsonPathParser.java:307) at org.jsfr.json.compiler.JsonPathParser.path(JsonPathParser.java:159) at org.jsfr.json.compiler.JsonPathCompiler.compile(JsonPathCompiler.java:283) at org.jsfr.json.compiler.JsonPathCompiler.compile(JsonPathCompiler.java:273) at org.jsfr.json.JsonSurfer.collectAll(JsonSurfer.java:262) at query.App.main(App.java:27) Caused by: org.antlr.v4.runtime.NoViableAltException at org.antlr.v4.runtime.atn.ParserATNSimulator.noViableAlt(ParserATNSimulator.java:2026) at org.antlr.v4.runtime.atn.ParserATNSimulator.execATN(ParserATNSimulator.java:467) at org.antlr.v4.runtime.atn.ParserATNSimulator.adaptivePredict(ParserATNSimulator.java:393) at org.jsfr.json.compiler.JsonPathParser.filterExpr(JsonPathParser.java:843) ... 7 more
For reference, the output was generated by the program in https://github.com/cburgmer/json-path-comparison/tree/master/implementations/Java_com.github.jsurfer.
I can try to fix the last case first
Due to the streaming nature of JsonSurfer, Case 2 and 3 with negative step are very hard to implement
Just out of curiosity, for a query $[-n]
you could keep a window with n
entries. When the stream stops you pick the first entry from that window and have your candidate.
The upper memory limit for the window would depend on the size of the entries in the list you are processing. This is very likely no different to what you are currently doing, just n
times (= constant) more.
Cool. It does make sense. I will try.
I've just reviewed source code and couldn't figure out a quick fix. So Case 2 & 3 won't be supported in near release