0

I have the following JSON:

{
  "signed": {
    "delegations": {
      "keys": {
        "blubb": {
          "keytype": "rsa-x509",
          "keyval": {
            "private": null,
            "public": "SomeOtherValue"
          }
        },
        "d8674eb06f5aac8d003b2f309e302fd0a82414074acc9a626e0b447704f2a2b8": {
          "keytype": "rsa-x509",
          "keyval": {
            "private": null,
            "public": "SomeValue"
          }
        }
      },
      "roles": [{
          "keyids": ["d8674eb06f5aac8d003b2f309e302fd0a82414074acc9a626e0b447704f2a2b8"],
          "name": "targets/abc",
          "paths": [""],
          "threshold": 1
        }, {
          "keyids": ["blubb"],
          "name": "targets/def",
          "paths": [""],
          "threshold": 1
        }
      ]
    }
  }
}

I want to get the "SomeValue" for the key with the same name as the roles.keyids[0] where the corresponding name is "targets/abc".

I tried the following:

$.signed.delegations.keys[?($.signed.delegations.roles[?(@name == 'targets/abc')])].keyval.public

But that doesn't work.

D.R.
  • 20,268
  • 21
  • 102
  • 205
  • I'm a little confused about what you expect your `SelectTokens()` query to return. The first query returns nothing; the second query returns 2 values: `SomeOtherValue` and `SomeValue`. Fiddle: https://dotnetfiddle.net/5nGqcP. Is that what you want? – dbc Jun 09 '20 at 14:27
  • No, I actually want it to return "SomeValue" only. The "working" query didn't work, I removed it from the question. I was mistaken. – D.R. Jun 09 '20 at 15:03
  • 1
    I'll be happy to be proven wrong, but this calls for nested filters, but AFAIK, these aren't supported by jsonpath. – Jack Fleeting Jun 09 '20 at 16:03
  • I see, hmm. I will use two queries then instead as a workaround. – D.R. Jun 10 '20 at 07:20

0 Answers0