How to assert deeply in JSON with python -


i trigerring api call, , server response in json format. response looks this:

{ "status": 0,  "not_passed": 1,  "why": [     {         "code": 229,          "reason": "some reason",       } ] } 

i need assert 2 thing. status , reason fro status using:

    r = requests.get_simple(url=server.my_server, params=p) data = json.loads(r.content) assert data["status"] == 0 

but doesn't work 'reason', maybe because 'reason' deeper in nested structure. how can fix one?

assert data['why'][0]['reason'] == 'something' 

of course assumes data['why'] exists, list, , contains dict first element.


Comments

Popular posts from this blog

php - Extract Text from HTTP referer -

java - Callback from new thread to class from which thread was initiated -

Receive udp packets in android gstreamer -