How to Get json value

91 views
Skip to first unread message

Aphirak Phothisa

unread,
Oct 28, 2019, 5:00:50 AM10/28/19
to robotframework-users
Hi' All
I  want to get the value from Json data when I get the API is return response.content on console below.
Please assist  me for resolve this issue.

image.png

niilo

unread,
Oct 29, 2019, 4:22:36 AM10/29/19
to robotframework-users
How about using RESTinstance library for API testing?

https://github.com/asyrjasalo/RESTinstance/blob/master/README.md

It's super easy to get the values from json object.

Kyle Epperson

unread,
Oct 29, 2019, 4:34:25 PM10/29/19
to robotframe...@googlegroups.com
This is an example of using the RequestsLibrary in robot that I use for API calls.

2019-10-29 13_34_03-Window.png

Aphirak Phothisa

unread,
Oct 29, 2019, 10:37:41 PM10/29/19
to kepp...@networkoptix.com, robotframework-users
 I can call API and return response json  value and than I want to get value id, first_name, middle_name, last_name, date_of_birth
from response below.

.{"status":"true","data":{"id":4357,"first_name":"APHIRAK","middle_name":"MAI","last_name":"PHOTHISA","date_of_birth":"19/12/1990"}}  

On Wed, Oct 30, 2019 at 3:34 AM Kyle Epperson <kepp...@networkoptix.com> wrote:
This is an example of using the RequestsLibrary in robot that I use for API calls.

2019-10-29 13_34_03-Window.png

--
You received this message because you are subscribed to the Google Groups "robotframework-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to robotframework-u...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/robotframework-users/7e5a67da-dbf5-4c34-9e87-a2b6a9ae96d7%40googlegroups.com.

Anthony fromtheuk

unread,
Oct 30, 2019, 11:04:14 AM10/30/19
to robotframe...@googlegroups.com
If you install jsonvalidator library, you can convert the response to a dictionary and then get your values out of the dictionary

*** Settings ***
Library             JsonValidator

*** Keywords ***
Set Dict
&{MYDICT}=   String To Json ${resp.content}
Log To Console ${MYDICT["data"]["id"]}
Log To Console ${MYDICT["data"]["first_name"]}
Log To Console ${MYDICT["data"]["middle_name"]}
Log To Console ${MYDICT["data"]["last_name"]}
Log To Console ${MYDICT["data"]["date_of_birth"]}




On Wednesday, 30 October 2019 02:37:41 UTC, Aphirak Phothisa wrote:
 I can call API and return response json  value and than I want to get value id, first_name, middle_name, last_name, date_of_birth
from response below.

.{"status":"true","data":{"id":4357,"first_name":"APHIRAK","middle_name":"MAI","last_name":"PHOTHISA","date_of_birth":"19/12/1990"}}  

On Wed, Oct 30, 2019 at 3:34 AM Kyle Epperson <kepp...@networkoptix.com> wrote:
This is an example of using the RequestsLibrary in robot that I use for API calls.

2019-10-29 13_34_03-Window.png



On Monday, October 28, 2019 at 2:00:50 AM UTC-7, Aphirak Phothisa wrote:
Hi' All
I  want to get the value from Json data when I get the API is return response.content on console below.
Please assist  me for resolve this issue.

image.png

--
You received this message because you are subscribed to the Google Groups "robotframework-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to robotframework-users+unsub...@googlegroups.com.

Kyle Epperson

unread,
Oct 30, 2019, 12:27:58 PM10/30/19
to robotframe...@googlegroups.com
This is how I pull the values out of the responses.  "bind system" is the api call that showed above.  "Setup Cloud System" is a call that uses some of the response data from bind.

2019-10-30 09_26_31-Window.png


Wentao Ma

unread,
Nov 11, 2019, 1:40:05 AM11/11/19
to robotframework-users
I use : JMESPath Tutorial — JMESPath 
def get_result(result,item,exptype='str'):
    '''From json get secific item '''
    rjs = json.loads(result)
    r_val = jmespath.search(item,rjs)
    if exptype == 'list':
        return list(r_val)
    return str(r_val)
Reply all
Reply to author
Forward
0 new messages