Reputation: 43
i received the following json as response:
{'statusCode': 200, 'Status': 'Success', 'GroupId': None, 'ActivityId': '8234560b-05d8-49a3-92c5-0ae6cea3ff80', 'MessageId': '3c326bb3-9798-4310-b95f-30135441090f', 'MessageType': 2, 'Payload': {'Result': {'Vid': {'Data': [{'label': 'lb1', 'Value': 1, 'Timestamp': '2020-09-01T09:31:30Z'}, {'label': 'lb2', 'Value': 2, 'Timestamp': '2020-09-01T09:31:30Z'}]}}}, 'Priority': 1, 'Time': '2020-09-01T09:37:17.8509538+00:00'}
i extracted "ActivityId" as follows:
${response['ActivityId']}
But how can i extract "Value" from "Data" array where "label" is "lb1"? itried this
${response['Payload']['Result']['Vid']['Data[?(@']['label=='lb1')]']['Value']}
got Syntax Error.
Upvotes: 2
Views: 2243
Reputation: 2813
Use the filter script expression of jsonpath ?()
to loop through the nodes of array on conditional basis.
${value}= Get Value From Json ${json_object} $.Payload.Result.Vid.Data[?(@.label=='lb1')].Value
log to console ${value}
Note: Put the string after == in single quotes and do not add the space between jsonpath expression
for more details on json path expression have a look at JSONLibrary
Output -
Upvotes: 1