wanglingsong / JsonSurfer

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

[BUG] Resumable parser does not accept $.[*] #88

Closed TheMessik closed 1 year ago

TheMessik commented 1 year ago

Basically the title.

I have following json file data.json

[]

And I'm trying to parse it using the JSONPath $.[*] with the ResumableParser:

JsonSurfer surfer = JsonSurferJackson.INSTANCE;
SurfingConfiguration config = JsonSurferJackson.INSTANCE
        .configBuilder()
        .bind(iterationPath, (value, context) -> {
            this.match = value;
            this.currentPath = context.getJsonPath();
            this.hasMatch = true;
            context.pause();
        })
        .build();
this.parser = surfer.createResumableParser(this.inputStream, config);
this.parser.parse();

with this.inputStream() being an InputStream from the file. I get following exception

line 1:2 no viable alternative at input '.[*]'

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.path(JsonPathParser.java:137)
    at org.jsfr.json.compiler.JsonPathCompiler.compile(JsonPathCompiler.java:283)
    at org.jsfr.json.SurfingConfiguration$Builder.bind(SurfingConfiguration.java:201)
    <truncated>
Caused by: org.antlr.v4.runtime.InputMismatchException
    at org.antlr.v4.runtime.BailErrorStrategy.recoverInline(BailErrorStrategy.java:61)
    ... 77 more

Truncated for brevity. The other lines relate to the JUnit framework and the specific class I'm running this in.

This path seems to not be accepted by the parser.

wanglingsong commented 1 year ago

try $[*] ?

TheMessik commented 1 year ago

That's how I ended up solving it, thank you!

Also learned that JSONPath is not standardized, so I'm not surprised this edge case is not handled. Consider this a non-issue

wanglingsong commented 1 year ago

That's how I ended up solving it, thank you!

Also learned that JSONPath is not standardized, so I'm not surprised this edge case is not handled. Consider this a non-issue

Thanks very much for you issue submission though