tidwall / gjson

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

Get multiple values using GetMany() not working #280

Closed leonj1 closed 2 years ago

leonj1 commented 2 years ago

Is it possible to select just the name and age from this json?

[ { "name": "frank", "dob": "foo", "age": 2" }, { "name": "annie", "dob": "bar", "age": 18 } ]

Using this, the array returns 2 Null Results

results := gjson.GetMany(input, "#.name", "#.age")

volans- commented 2 years ago

@leonj1 just to exclude the most obvious reason, the JSON you posted above has a typo: "age": 2" instead of "age": 2.

Did you get the unexpected result also with a valid JSON? I don't have handy the Go library, but on https://gjson.dev/ the query {#.name,#.age} returns as expected:

{"name":["frank","annie"],"age":[2,18]}
leonj1 commented 2 years ago

Dang! I missed that. Thanks!