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)
Answer from yash on Stack Overflow
🌐
GeeksforGeeks
geeksforgeeks.org › python › loop-through-a-json-array-in-python
Loop through a JSON array in Python - GeeksforGeeks
July 23, 2025 - You can loop through a JSON array in Python by using the json module and then iterating through the array using a for loop.
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']]
    
Discussions

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
How to parse JSON Array of objects in python - Stack Overflow
Possible duplicate of Convert string to JSON using Python if not, then it's an array which means its already parsed as json, so I'm not sure what you're asking in that case More on stackoverflow.com
🌐 stackoverflow.com
Convert JSON array to Python list - Stack Overflow
That is my JSON array, but I would want to convert all the values in the 'fruits' string to a Python list. More on stackoverflow.com
🌐 stackoverflow.com
Unable to append data to Json array object with desired output
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 ... More on discuss.python.org
🌐 discuss.python.org
0
0
January 18, 2023
🌐
ReqBin
reqbin.com › json › python › uzykkick › json-array-example
Python | What is JSON Array?
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. The following is an example of a JSON array with numbers. Below, you can find a list of JSON arrays with different data types. The Python code was automatically generated for the JSON Array example.
🌐
freeCodeCamp
freecodecamp.org › news › how-to-parse-json-in-python-with-examples
How to Parse JSON in Python – A Complete Guide With Examples
October 29, 2025 - JSON arrays represent ordered lists of values and appear frequently in API responses when returning collections of items. Python converts JSON arrays into lists, which you can iterate through or access by index.
🌐
W3Schools
w3schools.com › python › python_json.asp
Python JSON
Arrays Code Challenge Python Iterators · Iterators Code Challenge Python Modules · Modules Code Challenge Python Dates · Dates Code Challenge Python Math · Math Code Challenge Python JSON · JSON Code Challenge Python RegEx · RegEx Code Challenge Python PIP Python Try...Except ·
🌐
DataCamp
datacamp.com › tutorial › json-data-python
Python JSON Data: A Guide With Examples | DataCamp
December 3, 2024 - Learn how to work with JSON in Python, including serialization, deserialization, formatting, optimizing performance, handling APIs, and understanding JSON’s limitations and alternatives.
Find elsewhere
🌐
GeeksforGeeks
geeksforgeeks.org › python › python-json-to-list
Python Json To List - GeeksforGeeks
July 23, 2025 - In this example, the below code utilizes the `json.loads()` method to convert a JSON-formatted string `[1,2,3,4]` into a Python list named `array`. The `print` statements display the type of the original string, the first element of the resulting list, and the type of the converted 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...
🌐
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.

🌐
Medium
medium.com › @AlexanderObregon › how-to-work-with-json-in-python-aef62d28eac4
How to Work with JSON in Python | Medium
November 2, 2024 - JSON data is represented as text formatted in key-value pairs, similar to a Python dictionary · It supports primitive data types like strings, numbers, booleans, lists (arrays), and nested objects (dictionaries).
🌐
Real Python
realpython.com › python-json
Working With JSON Data in Python – Real Python
August 20, 2025 - For example, you can include an object as the value of an object. Also, you’re free to use any other allowed value as an item in a JSON array. As a Python developer, you may need to pay extra attention to the Boolean values.
🌐
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.
🌐
Python
docs.python.org › 3 › library › json.html
json — JSON encoder and decoder
3 weeks ago - The old version of JSON specified by the obsolete RFC 4627 required that the top-level value of a JSON text must be either a JSON object or array (Python dict or list), and could not be a JSON null, boolean, number, or string value.
🌐
Python Guides
pythonguides.com › json-data-in-python
How To Get Values From A JSON Array In Python?
November 29, 2024 - Let me show you another way to extract values from a JSON array is: by using list comprehension. List comprehension allows you to create a new list based on an existing list or iterable. Here’s an example: import json # Load JSON data from file with open('C:/Users/fewli/Downloads/Python/states.json') as file: data = json.load(file) state_names = [state['name'] for state in data] print("State Names:", state_names)
🌐
Vertabelo Academy
academy.vertabelo.com › course › python-json › reading-json-files › reading-json-files › json-with-arrays
How to Read and Write JSON Files in Python | Learn Python | Vertabelo Academy
Naturally, we can use it like a Python list – if we wanted information about the first employee in the list, we'd simply write: ... sum = 0 count = 0 for x in employees: sum += x["age"] count += 1 print("Mean age of employees", sum/count) Read the file named customers.json as customers.
🌐
Zyte
zyte.com › home › blog › json parsing with python [practical guide]
A Practical Guide to JSON Parsing with Python
July 6, 2023 - To access data within a JSON array, you can use array indexing, while to access data within an object, you can use key-value pairs.