tidwall / gjson

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

Get path based on url #363

Closed inuyasha-660 closed 4 months ago

inuyasha-660 commented 4 months ago

Sorry to bother you, I am not very good at English.

I hava a json like this

 "libraries": [
    {
      "downloads": {
        "artifact": {
          "path": "ca/weblite/java-objc-bridge/1.1/java-objc-bridge-1.1.jar",
          "sha1": "1227f9e0666314f9de41477e3ec277e542ed7f7b",
          "size": 1330045,
          "url": "https://libraries.minecraft.net/ca/weblite/java-objc-bridge/1.1/java-objc-bridge-1.1.jar"
        }
      },
      "name": "ca.weblite:java-objc-bridge:1.1",
      "rules": [
        {
          "action": "allow",
          "os": {
            "name": "osx"
          }
        }
      ]
    },
    {
      "downloads": {
        "artifact": {
          "path": "com/github/oshi/oshi-core/6.4.10/oshi-core-6.4.10.jar",
          "sha1": "b1d8ab82d11d92fd639b56d639f8f46f739dd5fa",
          "size": 979212,
          "url": "https://libraries.minecraft.net/com/github/oshi/oshi-core/6.4.10/oshi-core-6.4.10.jar"
        }
      },
      "name": "com.github.oshi:oshi-core:6.4.10"
    },
      "downloads": {
        "artifact": {
          "path": "org/slf4j/slf4j-api/2.0.9/slf4j-api-2.0.9.jar",
          "sha1": "7cf2726fdcfbc8610f9a71fb3ed639871f315340",
          "size": 64579,
          "url": "https://libraries.minecraft.net/org/slf4j/slf4j-api/2.0.9/slf4j-api-2.0.9.jar"
        }
      },
      "name": "org.slf4j:slf4j-api:2.0.9"
    }
 ],

Now, I can get all the url, Is there a way to get the corresponding path based on the URL? I hava seen the README and tried a few ways, but it seem don't work.

Json: https://piston-meta.mojang.com/v1/packages/177e49d3233cb6eac42f0495c0a48e719870c2ae/1.21.json

tidwall commented 4 months ago

So let's say you have the URL

https://libraries.minecraft.net/ca/weblite/java-objc-bridge/1.1/java-objc-bridge-1.1.jar

Using the GJSON path

libraries.#(downloads.artifact.url="https://libraries.minecraft.net/ca/weblite/java-objc-bridge/1.1/java-objc-bridge-1.1.jar").downloads.artifact.path

Returns the artifact path:

"ca/weblite/java-objc-bridge/1.1/java-objc-bridge-1.1.jar"
inuyasha-660 commented 4 months ago

It works fine, thanks for your help.