Search code examples
pythonpython-3.xrestautomated-testsrobotframework

Get Value From JSON using JSONPath returning null


Newbie here: I'm trying to get the id from the response body of a POST call. POST is successful but when I try to get the id and log it, it returns null. I think I'm simply missing a minor thing but yeah, need your help.

  ${response_body}    Decode Bytes To String    ${response.content}    encoding=utf-8     
  Set Test Variable    ${response_body}     
  Log    ${response_body}     
  ${id}    Get Value From Json    ${response_body}    id     
  Log    ${id}

Actual Response body is just:

    {
        "id": "546e0c4d-b810-49e6-a674-0d0f812bb790"
    }

Here is what I get in the reports:

report that shows id is empty

No errors, just blank value

I tried setting the response_body as the id as a whole but I get "id"="xxxxx..." when I call the ${id} so yeah I just need the value


Solution

  • Your problem is that ${response_body} is a string, not a JSON. You must use Convert String To Json to convert it to JSON before Get Value From Json works.