tidwall / gjson

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

result.Paths(json string) does not return paths when used more than one #'s #298

Open tanmaymishu opened 1 year ago

tanmaymishu commented 1 year ago

Hi, amazing work 👍

I have the following json:

{
  "people": [
    {"name": "John", "addresses": [{"zip": 123}]}
  ]
}

When I try to access the name property inside people, result.Paths() returns a slice of strings containing the path like this:

result := gjson.Get(string(json), field)
fmt.Println(result.Paths(string(json)))

people.#.name [people.0.name]

However when I do the same for the zip inside the addresses array,

people.#.addresses.#.zip

the result.Paths() no longer returns a slice of strings.

Is this a known limitation? If so, is there a workaround for this?

tanmaymishu commented 1 year ago

Looks like there is a similar issue: https://github.com/tidwall/gjson/issues/267