Get Values From Json ${resp_json()}

How can I get values from the key “createdAt” and “deviceid” and validate it in keyword?

{
    "content": [
        {
            "id": "23424564-a3423ae-324-2342-234324234",
            "version": 18,
            "createdAt": 1711459466029,
            "createdBy": "device",
            "modifiedAt": 1711705613758,
            "modifiedBy": "device2",
            "formattedCreatedAt": "2024-03-26T13:24:26.029Z",
            "deviceid": "test-device01",


}
]
}

I tried like that but … not working

${list_items} =    Create List    test-device01
${json_data} =  Get Value From Json  ${resp.json()}  $..createdAt['1711459466029']  $..deviceid['test-device01']
 List Should Contain Sub List    ${json_data}    ${list_items}

Is ${resp} the data returned from a requests library keyword?

If so ${resp.json()} is not a json_object but rather the method .json() converts the json string to a python dictionary.

Based on the JSON you showed you could do something like this:

${createdAt}=    Set Variable   ${resp.json()}[content][0][createdAt]
${deviceid}=    Set Variable   ${resp.json()}[content][0][deviceid]

Dave.

1 Like

Thank you so much Dave

1 Like