Open the file with any text editor. Add a [ at the very beginning of the file, and a ] at the very end. This will transform the data you have into an actual valid JSON array.

Then use the json module to work with it.

(EDITED CORRECTED VERSION BASED ON COMMENTS, thx @martin-novosad)

import json
with open("example.json") as f:
  arr = json.load(f)
# Do nifty stuff with resulting array.
Answer from FrobberOfBits on Stack Overflow
🌐
Zyte
zyte.com › home › blog › json parsing with python [practical guide]
JSON Parsing with Python [Practical Guide]
July 6, 2023 - We load the data using the with open() context manager and json.load() to load the contents of the JSON file into a Python dictionary. ... After loading JSON data into Python, you can access specific data elements using the keys provided in the JSON structure. In JSON, data is typically stored in either an array or an object.
🌐
Python Examples
pythonexamples.org › python-read-json-file
Python Read JSON File
The JSON data is an array of objects. data.json · [ { "a": 85, "b": 71, "c": 39 }, { "d": 18, "e": 72, "f": 23 }, { "g": 18, "h": 62, "i": 43 } ] import json fileObject = open("data.json", "r") jsonContent = fileObject.read() aList = json.loads(jsonContent) print(aList[0]) print(aList[0]['c']) {'a': 85, 'b': 71, 'c': 39} 39 · In this Python JSON Tutorial, we learned how to read JSON file in Python and access values from the JSON content.
🌐
Python
docs.python.org › 3 › library › json.html
JSON encoder and decoder — Python 3.14.3 documentation
Deserialize fp to a Python object using the JSON-to-Python conversion table. ... fp (file-like object) – A .read()-supporting text file or binary file containing the JSON document to be deserialized.
🌐
w3resource
w3resource.com › python-exercises › numpy › read-numeric-data-from-a-json-file-into-a-numpy-array.php
Read numeric data from a JSON file into a NumPy array
import numpy as np import json # Define the path to the JSON file json_file_path = 'sample.json' # Read the JSON file into a Python list with open(json_file_path, 'r') as json_file: data_list = json.load(json_file) # Convert the list to a NumPy array data_array = np.array(data_list) # Print the NumPy array print(data_array)
🌐
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)
Find elsewhere
🌐
W3Schools
w3schools.com › python › python_json.asp
Python JSON
Python Overview Python Built-in Functions Python String Methods Python List Methods Python Dictionary Methods Python Tuple Methods Python Set Methods Python File Methods Python Keywords Python Exceptions Python Glossary · Built-in Modules Random Module Requests Module Statistics Module Math Module cMath Module · Remove List Duplicates Reverse a String Add Two Numbers · Python Examples Python Compiler Python Exercises Python Quiz Python Challenges Python Server Python Syllabus Python Study Plan Python Interview Q&A Python Bootcamp Python Certificate Python Training ... JSON is a syntax for storing and exchanging data.
🌐
Real Python
realpython.com › python-json
Working With JSON Data in Python – Real Python
August 20, 2025 - When you load a JSON file as a Python object, then any JSON data type happily deserializes into Python. That’s because Python knows about all data types that the JSON format supports. Unfortunately, it’s not the same the other way around. As you learned before, there are Python data types like tuple that you can convert into JSON, but you’ll end up with an array data type in the JSON file.
🌐
Medium
medium.com › @AlexanderObregon › how-to-work-with-json-in-python-aef62d28eac4
How to Work with JSON in Python | Medium
November 2, 2024 - These tasks can be easily performed using Python’s built-in json module. Let’s explore different ways to read and write JSON data in more detail. To read JSON data from a file, you can use the json.load() function.
🌐
freeCodeCamp
freecodecamp.org › news › python-read-json-file-how-to-load-json-from-a-file-and-parse-dumps
Python Read JSON File – How to Load JSON from a File and Parse Dumps
October 27, 2020 - Notice the data types of the values, the indentation, and the overall structure of the file. The value of the main key "orders" is an array of JSON objects (this array will be represented as list in Python).
🌐
ReqBin
reqbin.com › code › python › g4nr6w3u › python-parse-json-example
How to parse a JSON with Python?
To convert a JSON file to a Python object using JSON Decoder, you can use the json.load() method (without the "s"), which has a syntax similar to json.loads() but accepts a file object instead of a string.
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']]
    
🌐
Stack Abuse
stackabuse.com › reading-and-writing-json-to-a-file-in-python
Reading and Writing JSON to a File in Python
April 18, 2023 - json.dump() - Serialized an object into a JSON stream for saving into files or sockets · Note: The "s" in "dumps" is actually short for "dump string". JSON's natural format is similar to a map in computer science - a map of key-value pairs. In Python, a dictionary is a map implementation, so we'll naturally be able to represent JSON faithfully through a dict. A dictionary can contain other nested dictionaries, arrays, booleans, or other primitive types like integers and strings.
🌐
PYnative
pynative.com › home › python › json › python json parsing using json.load() and loads()
Python JSON Parsing using json.load() and loads()
May 14, 2021 - Understand use of json.loads() and load() to parse JSON. Read JSON encoded data from a file or string and convert it into Python dict