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
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']]
    
๐ŸŒ
W3Schools
w3schools.com โ€บ python โ€บ python_json.asp
Python JSON
Python has a built-in package called json, which can be used to work with JSON data. ... If you have a JSON string, you can parse it by using the json.loads() method.
๐ŸŒ
ReqBin
reqbin.com โ€บ code โ€บ python โ€บ g4nr6w3u โ€บ python-parse-json-example
How to parse a JSON with Python?
Nested JSON objects will also be processed and included in the dictionary (see example below). To parse a JSON file, use the json.load() paired method (without the "s"). In this Python Parse JSON example, we convert a JSON data string into a ...
๐ŸŒ
Zyte
zyte.com โ€บ home โ€บ blog โ€บ json parsing with python [practical guide]
JSON Parsing with Python [Practical Guide]
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. ... In the example above, there is an object 'car' inside the JSON structure that contains two mappings ('model' ...
๐ŸŒ
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. Here's an example parsing a list of products from an inventory system:
๐ŸŒ
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.
๐ŸŒ
Temboo
temboo.com โ€บ python โ€บ parsing-json
Parsing JSON in Python
To do this, you'll use the following square bracket syntax for specifying the items array, then the first item in that array (at index 0), and finally the snippet object within the first item in the array: 7 To finish up, we assigned the title and description properties that are nested within the snippet object to local variables. title = data["items"][0]["snippet"]["title"] description = data["items"][0]["snippet"]["description"] 8All finished! Run the code to try it out. You should see the title of your first YouTube Search result in the console. Now you should to able to parse all sorts of JSON responses with our Python SDK.
Find elsewhere
๐ŸŒ
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 - 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.
๐ŸŒ
Python
docs.python.org โ€บ 3 โ€บ library โ€บ json.html
JSON encoder and decoder โ€” Python 3.14.3 documentation
If indent is a non-negative integer or string, then JSON array elements and object members will be pretty-printed with that indent level. An indent level of 0, negative, or "" will only insert newlines. None (the default) selects the most compact representation.
๐ŸŒ
Python Guides
pythonguides.com โ€บ json-data-in-python
How To Get Values From A JSON Array In Python?
November 29, 2024 - In this tutorial, I explained how to get values from a JSON array using Python. We learned how to parse JSON data, access values using loops and list comprehension, handle nested arrays, and filter data based on conditions.
๐ŸŒ
Oxylabs
oxylabs.io โ€บ blog โ€บ python-parse-json
Reading & Parsing JSON Data With Python: Tutorial
Here is a simple demonstration. This will open the file in writing mode and write the data in JSON format. Save this Python script in a file and run it. ... import json # Tuple is encoded to JSON array. languages = ("English", "French") # Dictionary is encoded to JSON object.
๐ŸŒ
Example Code
example-code.com โ€บ python โ€บ json_array_load_and_parse.asp
CkPython Loading and Parsing a JSON Array
Chilkat ย• HOME ย• Androidโ„ข ย• AutoIt ย• C ย• C# ย• C++ ย• Chilkat2-Python ย• CkPython ย• Classic ASP ย• DataFlex ย• Delphi DLL ย• Go ย• Java ย• Node.js ย• Objective-C ย• PHP Extension ย• Perl ย• PowerBuilder ย• PowerShell ย• PureBasic ย• Ruby ย• SQL Server ย• Swift ย• Tcl ย• Unicode C ย• Unicode C++ ย• VB.NET ย• VBScript ย• Visual Basic 6.0 ย• Visual FoxPro ย• Xojo Plugin
๐ŸŒ
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.

๐ŸŒ
Real Python
realpython.com โ€บ python-json
Working With JSON Data in Python โ€“ Real Python
August 20, 2025 - Learn how to work with JSON data in Python using the json module. Convert, read, write, and validate JSON files and handle JSON data for APIs and storage.
๐ŸŒ
GeeksforGeeks
geeksforgeeks.org โ€บ python โ€บ read-write-and-parse-json-using-python
Read, Write and Parse JSON using Python - GeeksforGeeks
August 28, 2025 - If you have JSON data stored in a .json file (for example, downloaded from an API or stored locally), Python's json module makes it easy to read and convert it into a Python dictionary using the json.load() function.
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?

๐ŸŒ
Python Forum
python-forum.io โ€บ thread-27109.html
Parse JSON multiple objects
I'm having trouble parsing multiple objects within a JSON array. I can get my code to work, but I have to manipulate the JSON file which I shouldn't have to do. I'm on Python 3, and here's my code: import json tradingList = [] print with open('par...
๐ŸŒ
ScrapingBee
scrapingbee.com โ€บ blog โ€บ how-to-read-and-parse-json-data-with-python
How to read and parse JSON data with Python | ScrapingBee
January 17, 2026 - This makes sense when you look at the conversion tables for both operations. Python converts both lists and tuples to a JSON array during encoding and then converts a JSON array into a Python list while decoding. So the data is the same but the data types are different.