In Extract variable policy I am unable to extract json array parameters from array

Not applicable

Below you can find my extract variable policy

<?xml version="1.0" encoding="UTF-8" standalone="yes"?> <ExtractVariables async="false" continueOnError="false" enabled="true" name="Extract-Variables-1"> <!--<Source>response</Source>--> <JSONPayload> <Variable name="programs"> <JSONPath>$.programs[:].programBrandCode</JSONPath> <!--<JSONPath>$.programs</JSONPath>--> </Variable> </JSONPayload> <VariablePrefix>programs</VariablePrefix> </ExtractVariables>

And my JSON array

{ "success": "true", "programs": [ { "programBrandCode": "TM", "programAvg": "0.1094" }, { "programBrandCode": "BE", "programAvg": "0.0000" }, { "programBrandCode": "21D", "programAvg": "0.0000" } ] }

using programBrandCode I need to hit one more API get the response and it should be post to the user

Added Javascript file to my API but I unable to run for loop below you can find the code for it

first I store the response into the programs variable, after that in for loop I add the condition of programs.length to run the loop, but here it gave me invalid programs length

var programs = context.proxyRequest;

for(i = 0; i<programs.length; i++){

Kindly tell me how can I extract attributes from JSON array.

Could I replace extract variable policy with javascript callout policy?

0 3 2,286
3 REPLIES 3

Not applicable

@rsekhar

I believe you can extract attributes from JSON array in a fashion where you need to provide index number for the particular variable , like the way as shown below for programBrandCode.programs-variable.jpg

 <?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<ExtractVariables async="false" continueOnError="false" enabled="true" name="Extract-Variables">
    <DisplayName>Extract Variables</DisplayName>
    <IgnoreUnresolvedVariables>true</IgnoreUnresolvedVariables>
    <Source>request.content</Source>
    <JSONPayload>
        <Variable name="programs" type="string">
            <JSONPath>$.programs[0].programBrandCode</JSONPath>
        </Variable>
    </JSONPayload>
</ExtractVariables>

Hi Umanng,

Using following JSON path $.programs[0].programBrandCode, we can get first item of porgrams brand code. But I need multiple items in an array.

In programs array we have multiple programBrandCode attributes. Using these attributes I need to call one more API to get the actual programs response.

so that I used following JSON path $.programs[:].programBrandCode, you can check json path on following website http://jsonpath.com/

Not applicable

The issue was resolved I used Javascript callout policy to resolved this issue.