Take a look at the json module. More specifically the 'Decoding JSON:' section.

import json
import requests

response = requests.get()  # api call

users = json.loads(response.text)
for user in users:
    print(user['id'])
Answer from Jim Wright on Stack Overflow
🌐
ReqBin
reqbin.com › json › python › uzykkick › json-array-example
Python | What is JSON Array?
The values of a JSON array are separated by commas. Array elements can be accessed by using the "[]" operator. Unlike dictionaries, where you can get the value by its key, in a JSON array, the array elements can only be accessed by their index.
Discussions

Python Parse JSON array - Stack Overflow
I'm trying to put together a small python script that can parse out array's out of a large data set. I'm looking to pull a few key:values from each object so that I can play with them later on in the script. Here's my code: # Load up JSON Function import json # Open our JSON file and load it ... More on stackoverflow.com
🌐 stackoverflow.com
python - Create array of json objects using for loops - Stack Overflow
I'm attempting to extract values from an html and then convert them into a json array, and so far I have been able to get what I want, but only as separate strings: I did two for loops: for line in More on stackoverflow.com
🌐 stackoverflow.com
Creating JSON Array of data with python
What I’m trying to do: I’m trying to retrieve the data from database and then create a JSON Array to send it to Google Gantt. What I’ve tried and what’s not working: I’m having propably problems with the conversion of python date to JSON date. Really I’m out of ideas how to do it ... More on anvil.works
🌐 anvil.works
1
0
August 22, 2023
Parsing muilti dimensional Json array to Python - Stack Overflow
By array, I think "most people" mean a - possibly multidimensional - data structure composed of elements all of the same type. JSON, and their Python couterpart "arbitrarily nested dicts and lists" are usually not arrays, but "objects", that's the whole point of it: something to "hold" an arbitrary ... More on stackoverflow.com
🌐 stackoverflow.com
🌐
Delft Stack
delftstack.com › home › howto › python › parse json array of objects in python
How to Parse JSON Array of Objects in Python | Delft Stack
February 2, 2024 - The JSON data string is parsed by the json.loads() function, which then provides a Python dictionary with all of the data from the JSON. You may get parsed data from this Python dictionary by using names or indexes to refer to objects. We can also examine the dictionary for nested JSON items. Use the associated method json.load() to parse a JSON file (without the s). we have used json.loads for parsing the values in the array in the below example.
🌐
Educative
educative.io › answers › how-to-pretty-print-json-objects-in-python
How to pretty print JSON objects in Python
We come across JSON arrays when we receive a response from a web API or deal with JSON files. A JSON array is a collection of JSON objects where a comma separates each JSON object.
🌐
JSON Schema
json-schema.org › understanding-json-schema › reference › array
JSON Schema - array
Arrays are used for ordered elements. In JSON, each element in an array may be of a different type. ... In Python, "array" is analogous to the list or tuple type, depending on usage.
🌐
W3Schools
w3schools.com › python › python_json.asp
Python JSON
The json.dumps() method has parameters to make it easier to read the result: Use the indent parameter to define the numbers of indents: ... You can also define the separators, default value is (", ", ": "), which means using a comma and a space to separate each object, and a colon and a space to separate keys from values:
Find elsewhere
🌐
CodeUtility
blog.codeutility.io › programming › how-to-use-arrays-in-json-with-examples-in-code-5eeef2665f
How to use Arrays in JSON (With Examples in Code) | CodeUtility
September 26, 2025 - This structure is both flexible and powerful, allowing you to perform operations like filtering, sorting, updating, and serializing easily with native Python features such as list comprehensions, sorted(), and dictionary unpacking. import json # Sample JSON array of objects (Python list of dicts) users = [ { "name": "Alice", "active": True }, { "name": "Bob", "active": False }, { "name": "Carol", "active": True } ] # 1.
Top answer
1 of 2
46

In your for loop statement, Each item in json_array is a dictionary and the dictionary does not have a key store_details. So I modified the program a little bit

import json

input_file = open ('stores-small.json')
json_array = json.load(input_file)
store_list = []

for item in json_array:
    store_details = {"name":None, "city":None}
    store_details['name'] = item['name']
    store_details['city'] = item['city']
    store_list.append(store_details)

print(store_list)
2 of 2
0

If you arrived at this question simply looking for a way to read a json file into memory, then use the built-in json module.

with open(file_path, 'r') as f:
    data = json.load(f)

If you have a json string in memory that needs to be parsed, use json.loads() instead:

data = json.loads(my_json_string)

Either way, now data is converted into a Python data structure (list/dictionary) that may be (deeply) nested and you'll need Python methods to manipulate it.


If you arrived here looking for ways to get values under several keys as in the OP, then the question is about looping over a Python data structure. For a not-so-deeply-nested data structure, the most readable (and possibly the fastest) way is a list / dict comprehension. For example, for the requirement in the OP, a list comprehension does the job.

store_list = [{'name': item['name'], 'city': item['city']} for item in json_array]
# [{'name': 'Mall of America', 'city': 'Bloomington'}, {'name': 'Tempe Marketplace', 'city': 'Tempe'}]

Other types of common data manipulation:

  1. For a nested list where each sub-list is a list of items in the json_array.

    store_list = [[item['name'], item['city']] for item in json_array]
    # [['Mall of America', 'Bloomington'], ['Tempe Marketplace', 'Tempe']]
    
  2. For a dictionary of lists where each key-value pair is a category-values in the json_array.

    store_data = {'name': [], 'city': []}
    for item in json_array:
        store_data['name'].append(item['name'])
        store_data['city'].append(item['city'])
    # {'name': ['Mall of America', 'Tempe Marketplace'], 'city': ['Bloomington', 'Tempe']}
    
  3. For a "transposed" nested list where each sub-list is a "category" in json_array.

    store_list = list(store_data.values())
    # [['Mall of America', 'Tempe Marketplace'], ['Bloomington', 'Tempe']]
    
🌐
Pythonspot
pythonspot.com › json-encoding-and-decoding-with-python
python json - Python Tutorial
Converting JSON data to Python objects JSON data can be converted (deserialized) to Pyhon objects using the json.loads() function. A table of the mapping:
🌐
GeeksforGeeks
geeksforgeeks.org › python › loop-through-a-json-array-in-python
Loop through a JSON array in Python - GeeksforGeeks
July 23, 2025 - A JSON array is an ordered list of values that can store multiple values such as string, number, boolean, or object. The values in a JSON array must be separated by commas and enclosed in squares in brackets []. In this article, we will learn ...
Top answer
1 of 2
13

After you parse the JSON, you will end up with a Python dict. So, suppose the above JSON is in a string named input_data:

import json
# This converts from JSON to a python dict
parsed_input = json.loads(input_data)

# Now, all of your static variables are referenceable as keys:
secret = parsed_input['secret']
minutes = parsed_input['minutes']
link = parsed_input['link']

# Plus, you can get your bookmark collection as:
bookmark_collection = parsed_input['bookmark_collection']

# Print a list of names of the bookmark collections...
print bookmark_collection.keys() # Note this contains sublinks, so remove it if needed

# Get the name of the Boarding Pass bookmark:
print bookmark_collection['boarding_pass']['name']

# Print out a list of all bookmark links as:
#  Boarding Pass
#    * 1: http://www.1.com/
#    * 2: http://www.2.com/
#  ...
for bookmark_definition in bookmark_collection.values():
    # Skip sublinks...
    if bookmark_definition['name'] == 'sublinks':
        continue
    print bookmark_definition['name']
    for bookmark in bookmark_definition['bookmarks']:
        print "    * %(name)s: %(link)s" % bookmark

# Get the sublink definition:
sublinks = parsed_input['bookmark_collection']['sublinks']

# .. and print them
print sublinks['name']
for link in sublinks['link']:
    print '  *', link
2 of 2
2

Hmm, doesn't json.loads do the trick?

For example, if your data is in a file,

import json
text = open('/tmp/mydata.json').read()

d = json.loads(text)

# first level fields
print d['minutes'] # or 'secret' or 'link'

# the names of each of bookmark_collections's items
print d['bookmark_collection'].keys()

# the sublinks section, as a dict
print d['bookmark_collection']['sublinks']

The output of this code (given your sample input above) is:

20
[u'sublinks', u'free_link', u'boarding_pass']
{u'link': [u'http://www.1.com', u'http://www.2.com', u'http://www.3.com'], u'name': u'sublinks'}

Which, I think, gets you what you need?

🌐
Reddit
reddit.com › r/learnpython › extremely confused with parsing a json array
r/learnpython on Reddit: Extremely confused with parsing a JSON array
April 14, 2017 -

Hi everyone. I'm really, really confused about parsing a JSON array.

For my script, I'll need to use a reverse geocoder, and I've decided to use Google's. I'm requesting a JSON, and it's returning this: https://developers.google.com/maps/documentation/geocoding/intro#reverse-example.

What I can't seem to figure out is the proper way of parsing it. I'm trying to extract the long_name in a few different types (for this example, let's say route, neighborhood, and administrative_area_level_2), and pass each long name for each type as their own string.

I'm completely lost on how to go about parsing this. I've tried json.loads, and doing a bunch of other things that fail in a "list indices must be integer", or unexpected results.

Right now, this is the nieve code I'm using to at least print long_name (about 30 times):

reverse_json = json.load(reader(reverseJSON))
# Excuse the debugging
print(reverse_json) 

for data in reverse_json['results']:
    address = data['address_components']
    for data in address:
        address = data['long_name']
        print(address)

And if I add on this to the final for loop:

if data['types'] == "['route']":
    address = data['long_name']
    print(address)

I get nothing.

json.loads doesn't help, either. It just results in

TypeError: the JSON object must be str, bytes or bytearray, not 'StreamReader'

So, I'm stuck with trying to parse a JSON array, and to have "long_name" become a certain variable if a certain type occurs. It's confusing to me, hopefully it isn't to you.

A simple explanation and help would be appreciated.

🌐
Stack Overflow
stackoverflow.com › questions › 38176182 › how-to-create-an-array-of-objects-in-json-using-python
How to create an array of objects in JSON, using python? - Stack Overflow
May 23, 2017 - I actually think this question is a bit different, since it is asking how to take any number of lists. At least, it is not an exact duplicate. ... As pointed out below my answer is incorrect because lists do not have names but you could try to combine it with this answer to set up something that aims at what you are trying to do ... names = [a.__name__ for a in arrays] objs = [] For arrs in zip(arrays): objs.append({"array_" + n: val for n, val in zip(names, arrs)})
🌐
Stack Overflow
stackoverflow.com › questions › 70578104 › how-do-i-create-json-array-of-objects-using-python
How do I create json array of objects using python - Stack Overflow
Python obviously has no way to know that you are writing a list of objects when you are writing them one at a time ... so just don't. cells = soup.table('td') cities = [] for cell in cells[:-2]: cities.append({"country": str(cells[count].getText()), "city": str(cells[count].next_sibling.getText())}) json.dump(cities, cities_list)
🌐
Python.org
discuss.python.org › python help
Unable to append data to Json array object with desired output - Python Help - Discussions on Python.org
January 18, 2023 - I’m tried getting help for same issue on stack-overflow but got no help or replies. I’m re-posting here with the hope that someone can please guide me as I’m unable to push the code to repository due to delay. My code import json import re from http.client import responses import vt import requests with open('/home/asad/Downloads/ssh-log-parser/ok.txt', 'r') as file: file = file.read() pattern = re.compile(r'\\d{1,3}.\\d{1,3}.\\d{1,3}.\\d{1,3}') ips = pattern.findall(file) unique_ips = lis...