wanglingsong / JsonSurfer

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

Is it possible to make multiple queries in one jsonPath? #79

Closed usatenko closed 1 year ago

usatenko commented 1 year ago

So, my JSON is:

{
  "key1": "val1",
  "key2": "val2",
  "key3": [
    {"key3.1": "val3.1"},
    {"key3.2": "val3.2"}
  ]
}

I use a non-blocking Jackson processor and would need to query all 3 keys at a time. But the problem it does not work for me. $['key1','key2','key3'] does not give me key3 value (it actually gives but the amount of data under key3 is huge, so the nonblocking processor will assemble it for long-long time). $['key1','key2','key3'][*] does not give me key1 and key2 values. I would want something like $[key1, key2, key3[*]] or $[@.key1, @.key2, @.key3[*]] This approach will allow me to get key1, key2 and skip assembling key3 array but go by it's elements one by one.

Is it somehow possible?

usatenko commented 1 year ago

Ignore this, I just found a solution. You can actually bind several jsonPaths.

            SurfingConfiguration config = surfer.configBuilder()
                    .bind(JsonPathCompiler.compile(path1), JsonNode.class, jsonNodeTypedJsonPathListener)
                    .bind(JsonPathCompiler.compile(path2), JsonNode.class, jsonNodeTypedJsonPathListener)
                    .build();