How to extract value from JSON array object and assign to Assign message

I am having a issue extracting values from a json array object that the array is dynamic therefore i can expect 2 array objects or 'n' object(s)...

now how can i extract these dynamic values from response and set to assign message.

for example:

{
    
    "DateTime": "0119224502",
    "ResponseCode": "00",
    "StudentList": [
        {
            "RELATIONSHIP_NUM": "185426",
            "STUDENT_ID": "60244",
            "STUDENT_STATUS_CODE": "001",
            "NAME": "Ali"
         },
        {
               "RELATIONSHIP_NUM": "185427",
            "STUDENT_ID": "60245",
            "STUDENT_STATUS_CODE": "001",
            "NAME": "AZEEM"
                 }
    ]
}

now this StudentList is current giving 2 array objects in response but i can expect 'n' array obects in response.

Solved Solved
0 7 7,798
1 ACCEPTED SOLUTION

thread solved... what i have done is that i used ExtractVariables with ther following path to extract the data:

 <Variable name="SList">
       <JSONPath>$.StudentList[*]</JSONPath>
 </Variable>

and then later to assign it:

{"StudentList":{
                {SList}
    }
}

I hope it might help someone who faces the same type of issue 🙂

View solution in original post

7 REPLIES 7

What is the desired output?

You are showing an example input, and I understand there might be 2 elements in the StudentList array, or there might be more than 2.

What do you want to get out of that?

What do you want to map that input to?

thread solved... what i have done is that i used ExtractVariables with ther following path to extract the data:

 <Variable name="SList">
       <JSONPath>$.StudentList[*]</JSONPath>
 </Variable>

and then later to assign it:

{"StudentList":{
                {SList}
    }
}

I hope it might help someone who faces the same type of issue 🙂

This is working fine, when the array have more than 2 records. But if the array has only one record, Data won't be extracted

Example please.

HI @Dino, Thank you for prompt attention. It's working fine. No issue. Ignore my above comment.

what if the assign Message policy is in xml format? Please explain how to pass this array in xml type of assign message policy.

rssabandal
Participant I

Hello,

I know the thread is already solved but I would also like to offer an alternative solution. You can parse the JSON using the javascript policy then set the value to a variable.

Sample JS policy:

var requestContent = context.getVariable('request.content');
var assignMessagePayload = "";

requestContent = JSON.parse(requestContent);
var studentsList = requestContent.StudentList;
assignMessagePayload.StudentList = studentsList;
context.setVariable('assignMessagePayload', JSON.stringify('assignMessagePayload'));
 
Sample assign message:
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<AssignMessage async="false" continueOnError="false" enabled="true" name="AM-SetRequestContent">
    <DisplayName>AM-SetRequestContent</DisplayName>
    <Properties/>
    <Set>
        <Payload>{assignMessagePayload}</Payload>
        <Verb>POST</Verb>
    </Set>
    <IgnoreUnresolvedVariables>true</IgnoreUnresolvedVariables>
    <AssignTo createNew="true" transport="http" type="request"/>
</AssignMessage>

 

Hope it helps!

Ryan