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

Extract variables from json using filter expression

Not applicable

Hi All, I am facing an issue to Extract variables with JSONPath on a ExtractVariables policy using filter expression: The ExtractVariables policy:

<ExtractVariables name="Extract-License">
  <DisplayName>Extract my License</DisplayName>
  <IgnoreUnresolvedVariables>true</IgnoreUnresolvedVariables>
  <Source>refresponse</Source>
  <VariablePrefix>refvars</VariablePrefix>
  <JSONPayload>
    <Variable name="mylicense">
      <JSONPath>$.licenses[?(@.uri = 'somelicense')].status</JSONPath>
    </Variable>
  </JSONPayload>
</ExtractVariables>

This get executed after a successful ServiceCallout that returns :

{
  "result": "ok",
  "message": "licenses",
  "licenses": [{
    "uri": "http://0-www.crossref.org.libcat.lafayette.edu/tdm_license",
    "status": "accepted",
    "reviewed_at": "2013-07-02T14:52:06+00:00"
  }, {
    "uri": "somelicense",
    "status": "accepted",
    "reviewed_at": "2013-07-02T14:52:06+00:00"
  }]
} 

If I replace the JSONPath expression with

$.licenses[1].status

... it works as expected.

What's wrong with the first expression? Thanks for your help

Solved Solved
0 10 9,574
1 ACCEPTED SOLUTION

Not applicable

We finally managed to get it working, this happens only if we use VariablePrefix, when I removed it worked fine. (@dzuluaga the the application/json header was already set in the response)

Thanks you all for you help.

View solution in original post

10 REPLIES 10