tidwall / gjson

Get JSON values quickly - JSON parser for Go
MIT License
14.39k stars 857 forks source link

Wildcards cannot get all values #358

Closed inuyasha-660 closed 6 months ago

inuyasha-660 commented 6 months ago

I have a long JSON like this

"objects": {
    "icons/icon_128x128.png": {
      "hash": "b62ca8ec10d07e6bf5ac8dae0c8c1d2e6a1e3356",
      "size": 9101
    },
    "icons/icon_16x16.png": {
      "hash": "5ff04807c356f1beed0b86ccf659b44b9983e3fa",
      "size": 781
    },
    "icons/icon_256x256.png": {
      "hash": "8030dd9dc315c0381d52c4782ea36c6baf6e8135",
      "size": 19642
    }
}

And i want to get all hash, i try to use `objects.*.hash` to get it ,but it only get the first hash b62ca8ec10d07e6bf5ac8dae0c8c1d2e6a1e3356

My code

    Object_Hash := gjson.Get(string(indexFile), `objects.*.hash`)
    println(Object_Hash.String())

json: https://piston-meta.mojang.com/v1/packages/9bc63c380207a6a967e5ff6315e645e4085135e5/16.json

volans- commented 6 months ago

@inuyasha-660 If you have gjson v1.16.0 or later you can use the @dig modifier with: @dig:hash. It will return a list of hashes. See e8e87f2 for more details.

inuyasha-660 commented 6 months ago

@inuyasha-660 如果您拥有 gjson v1.16.0 或更高版本,则可以使用@dig修饰符:@dig:hash。它将返回哈希列表。有关更多详细信息,请参阅e8e87f2 。

Thanks to you, it worked successfully