Get hands-on experience with 20+ free Google Cloud products and $300 in free credit for new customers.

How to extract one attribute of json payload stored in a variable

Hi I have a public key in below format stored in a varible called "cached.jwk". I want to get value of kid.

Data

{
    "keys": [
        {
            "kty": "RSA",
            "alg": "RS256",
            "kid": "xyz123",
            "use": "sig",
            "e": "AQAB",
            "n": "abslkfjsflksdfjs"
        }
    ]
}

please let me know how I can do that. I tried Extract variable policy, but it is not working.

<ExtractVariables name="Extract-Variables-1">
  <DisplayName>Extract Variables-1
  </DisplayName>
  <Source>cached.jwk</Source>
  <JSONPayload>
    <Variable name="cachedkid">
      <JSONPath>$.keys..kid</JSONPath>
    </Variable>
  </JSONPayload>
</ExtractVariables>

Thank you

Solved Solved
0 8 2,354
1 ACCEPTED SOLUTION

Your policy looks correct as far as I can see. Have you done a trace to confirm cached.jwk contains the expected value and what is getting populated into cacedkid? You should be able to see this tracing the extract variables policy.

With that said looking at your json structure, keys contains an array. Is that expected? I believe your current use of extract variables would return an array of strings from your structure.

If you don't actually intend to use an array for keys, your structure would be

{ "keys": { "kty": "RSA", "alg": "RS256", "kid": "xyz123", "use": "sig", "e": "AQAB", "n": "abslkfjsflksdfjs" }  }

in which case the json path would be

$.keys.kid

View solution in original post

8 REPLIES 8