0

I'm a newb with JSON and am trying to understand how to parse a JSON response. In the example below, I'd like to know how to retrieve the value of 'issueId':'executions':'id'? in the example below it is '8195'.....

r = requests.get(baseURL + getExecutionsForIssueId + id, auth=('user','pass'))
data = r.json()


JSON Response:
    {
        "status": {
            "1": {
                "id": 1,
                "color": "#75B000",
                "description": "Test was executed and passed successfully.",
                "name": "PASS"
             },
            "2": {
                "id": 2,
                "color": "#CC3300",
                "description": "Test was executed and failed.",
                "name": "FAIL"
            },
            "3": {
    .
    .
    .
        }
    },
    "issueId": 15825,
    "executions": [
        {
            "id": 8195,
            "orderId": 7635,
            "executionStatus": "-1",
            "comment": "",
            "htmlComment": "",
.
.
.
2
  • 1
    data['issueId']? Commented Aug 16, 2016 at 16:28
  • 1
    I just answered a question very similar that might help you for more complex json. There's lots of examples for this kind of thing. Commented Aug 16, 2016 at 16:34

1 Answer 1

1

Your JSON object is just a dictionary in Python. Access the values you need like so:

data['executions'] yields an array of similar dictionary objects, assuming your JSON response is typed as you intended.

executions = data['executions']
order_id = executions[0]['orderId']

If you wish to loop over them to find the correct object with an id of 8195:

executions = data['executions'] # [{'id':8195,'orderId':7635,...}, {...}, ...]
for e in executions:
    if e['id'] == 8195: # e is the dict you want
        order_id = e['orderId']
Sign up to request clarification or add additional context in comments.

1 Comment

I've changed the original question above to "I'd like to know how to retrieve the value of 'issueId':'executions':'id'? in the example below it is '8195'..... " . In order to accomplish this: execution = data['executions'] execId = execution[0]['id']

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.