tidwall / gjson

Get JSON values quickly - JSON parser for Go
MIT License
13.88k stars 841 forks source link

Querying for multiple values in one pass #349

Closed purplefox closed 4 months ago

purplefox commented 4 months ago

First of all.. thanks for gjson- it's great!

I guess this is a feature request (?)

I have a deeply nested JSON object and I would like to query for multiple fields in it, e.g. the following paths:

a.b.c.d.e.f.g.h.i.j.k1 a.b.c.d.e.f.g.h.i.j.k2 a.b.c.d.e.f.g.h.i.j.k3

All the paths I want to query are close together and deep in the object. I can query them all one by one which works fine, but each query requires a new scan from the root of the object each time.

I was wondering, as an optimisation, is gjson able to support querying for multiple paths in one scan? That way it could return k1, k2 and k3 in one scan of the json, and since k1, k2 and k3 are close together this would be much more efficient than 3 separate scans.

purplefox commented 4 months ago

Closing this, as I could just precompute that k1, k2, and k3 are hanging off a.b.c.d.e.f.g.h.i.j and simply query that.