tyrell_c tyrell_c - 3 months ago 12
JSON Question

How to iterate through this nested json array with python

So I made an API call to JIRA to get the list of all the issues. It returns something like this:

{
issues: [
{
fields: {
description:
summary:
creator:
reporter:
priority:
}
}
]


and I'm trying to get to what's inside
fields
.
Here's what I have:

response = requests.get(url + '/search?jql=resolution%20=%20Unresolved%20order%20by%20priority%20DESC,updated%20DESC', auth=auth).json()


and then :

response['issues']
works. But I can't find a way to access
fields
and then the elements inside it. I thought about iterating through but not sure if there's a simpler solution.

My understanding is that response[issues] is a list and I know how to access each element of it
response[issues][0]
but how to access the object nested inside the list? (still researching on it -- might find an answer)

Answer

if you look at your json it's an array to a hash or list to dict. To get fields you'd just call the first array element and the key.

response[issues][0][fields]

Comments