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
47

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
1

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']]
    
🌐
GeeksforGeeks
geeksforgeeks.org › python › loop-through-a-json-array-in-python
Loop through a JSON array in Python - GeeksforGeeks
July 23, 2025 - In this example, we will define the JSON data as a string and load it using the and the load() function to convert the JSON data to a Python object. Then using a for loop we will iterate through the array.
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
Accessing data from a json array in python - Stack Overflow
Usually the json will be a string and you will try and deserialise it into a object graph (which in python are typically are made up of maps and arrays). More on stackoverflow.com
🌐 stackoverflow.com
How to convert nested list into JSON?
json.dumps can handle nested data structures, too. More on reddit.com
🌐 r/learnpython
6
3
June 23, 2018
Python pandas: convert a list of JSON strings into a dataframe. How do I do that?
Start here: https://pandas.pydata.org/docs/reference/api/pandas.json_normalize.html More on reddit.com
🌐 r/learnpython
9
3
April 4, 2023
🌐
W3Schools
w3schools.com › python › python_json.asp
Python JSON
If you have a JSON string, you can parse it by using the json.loads() method. The result will be a Python dictionary.
🌐
JSON Schema
json-schema.org › understanding-json-schema › reference › array
JSON Schema - array
Tuple validation is useful when the array is a collection of items where each has a different schema and the ordinal index of each item is meaningful. For example, you may represent a street address such as 1600 Pennsylvania Avenue NW as a 4-tuple of the form:
🌐
Python
docs.python.org › 3 › library › json.html
json — JSON encoder and decoder
indent (int | str | None) – If a positive integer or string, JSON array elements and object members will be pretty-printed with that indent level. A positive integer indents that many spaces per level; a string (such as "\t") is used to indent each level. If zero, negative, or "" (the empty string), only newlines are inserted.
🌐
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 - The JSON string starts with a square bracket, indicating an array at the root level. After parsing, products is a Python list containing three dictionaries.
Find elsewhere
🌐
Heardlibrary
heardlibrary.github.io › digital-scholarship › script › python › json
Dictionaries and JSON | Digital Education Resources - Vanderbilt Libraries Digital Lab
In the same way that JSON objects can be nested within arrays or arrays nested within objects, Python dictionaries can be nested within lists or lists nested within dictionaries. So pretty much any JSON data structure can be translated into a complex Python data object. There is a Python library, appropriately called the json module, that will convert a JSON string into a Python data object and vice versa. First example: JSON array nested inside a object (Python list inside a dictionary)
🌐
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 ...
🌐
freeCodeCamp
freecodecamp.org › news › how-to-pretty-print-json-in-python
How to Pretty Print JSON in Python
April 14, 2023 - We will also cover best practices used to pretty print JSON, and also talk about it's use cases. In Python, "pretty print" refers to formatting and presenting data structures such as lists, dictionaries, and tuples in a more readable and organized way.
🌐
Zyte
zyte.com › home › blog › json parsing with python [practical guide]
JSON Parsing with Python [Practical Guide]
December 3, 2024 - For example, you can use JMESPath to filter a list of objects based on a specific value or to extract specific parts of an object and transform them into a new structure. Let's say we have a JSON array of car objects, each containing information such as the car's make, model, year and price...
🌐
Esri Community
community.esri.com › t5 › python-questions › python-to-generate-dynamic-nested-json-string › td-p › 257817
Solved: Python to Generate Dynamic Nested JSON String - Esri Community
December 11, 2021 - Yes it was my own "freehand" JSON provided as an example to show the key value pairs in a single array as they exist in their original dictionary structure and not separated out into "fields": and "values": arrays.
🌐
MDN Web Docs
developer.mozilla.org › en-US › docs › Learn_web_development › Core › Scripting › JSON
Working with JSON - Learn web development | MDN
2 weeks ago - Inside the powers property is an array containing the selected hero's superpowers. We want the third one, so we use [2]. The key takeaway is that there's really nothing special about working with JSON; after you've parsed it into a JavaScript object, you work with it just like you would with an object declared using the same object literal syntax. Note: We've made the JSON seen above available inside a variable in our JSONTest.html example (see the source code).
🌐
W3Schools
w3schools.com › js › js_json_server.asp
JSON Arrays
Well organized and easy to understand Web building tutorials with lots of examples of how to use HTML, CSS, JavaScript, SQL, Python, PHP, Bootstrap, Java, XML and more.
🌐
ReqBin
reqbin.com › code › python › g4nr6w3u › python-parse-json-example
How to parse a JSON with Python?
You can access an element from a JSON array by its index in a Python object.
🌐
DataCamp
datacamp.com › tutorial › json-data-python
Python JSON Data: A Guide With Examples | DataCamp
December 3, 2024 - This option allows you to specify the separators used in the output JSON string. The separators parameter takes a tuple of two strings, where the first string is the separator between JSON object key-value pairs, and the second string is the separator between items in JSON arrays. For example:
🌐
Like Geeks
likegeeks.com › home › python › 5 methods to split json array in python
5 Methods To Split JSON array in Python
January 23, 2024 - In this output, the original array has been divided into two halves. The mid_index determines the splitting point, ensuring an even distribution of data between first_half and second_half. You can split JSON array based on conditions using list comprehensions.
🌐
SitePoint
sitepoint.com › blog › programming › working with json files in python, with examples
Working with JSON Files in Python, with Examples — SitePoint
November 7, 2024 - For instance, Python’s ‘dict’ is equivalent to JSON’s ‘object’, and Python’s ‘list’ or ‘tuple’ is equivalent to JSON’s ‘array’. This mapping helps in the conversion processes between Python and JSON. In this tutorial, we’ll learn how to read, write and parse JSON in Python with relevant examples.
🌐
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 typically represented ... JSON arrays) in Python, making it convenient to access, modify, add, or delete data. To access nested values in a JSON object, you can use dictionary keys and list indices just as you would with a regular Python dictionary or list. Here’s an example...