You're trying to read the string "data.txt". What you want is to open and read the file.

import json

with open('data.txt', 'r') as data_file:
    json_data = data_file.read()

data = json.loads(json_data)
Answer from Agustín Lado 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

How to parse JSON Array of objects in python - Stack Overflow
Copy[{ "username": "username_1", ... such objects>..] Given that typeof(response) gives me requests.models.Response, how can I parse it in Python? ... You need to use the json module. ... Possible duplicate of Convert string to JSON using Python if not, then it's an array which means ... More on stackoverflow.com
🌐 stackoverflow.com
How to create an array of objects in JSON, using python? - Stack Overflow
I have the following arrays: A=[1,2,3] B=[6,7,8] I would like to compose them into JSON format, specifically, as an array of objects. I am trying to write a function that will accept multiple arra... More on stackoverflow.com
🌐 stackoverflow.com
May 23, 2017
How do I create json array of objects using python - Stack Overflow
I have a list of countries and their cities on one website. I take all names of countries and their capitals from this list, and want to put them in JSON file like this: [ { "country&quo... More on stackoverflow.com
🌐 stackoverflow.com
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
🌐
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.
🌐
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 ...
🌐
Tech With Tech
techwithtech.com › home › json object vs. json array explained with python
JSON Object vs. JSON Array Explained With Python - Tech With Tech
November 6, 2022 - JSON arrays are structured the same as Python bracketed lists. They can have the same data types as the JSON object field values, including nested arrays. Let’s add a battery field to the JSON object above, its value is a JSON array.
🌐
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)})
Find elsewhere
🌐
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)
🌐
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:
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']]
    
🌐
JSON Schema
json-schema.org › understanding-json-schema › reference › array
JSON Schema - array
However, the json module in the Python standard library will always use Python lists to represent JSON arrays. ... List validation: a sequence of arbitrary length where each item matches the same schema.
🌐
Example Code
example-code.com › python › json_array_load_and_parse.asp
Loading and Parsing a JSON Array | Chilkat Examples
See more JSON Examples A JSON array is JSON that begins with "[" and ends with "]". For example, this is a JSON array that contains 3 JSON objects.
🌐
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.
🌐
Python Guides
pythonguides.com › json-data-in-python
How to Extract Values from a JSON Array in Python
April 27, 2026 - In this tutorial, I showed you several ways to get values from a JSON array in Python. Depending on your specific needs, whether it’s a simple loop, a quick list comprehension, or handling nested objects, you can choose the method that works best for you.
🌐
py4u
py4u.org › blog › python-read-in-an-array-of-json-objects-using-json-loads
How to Read an Array of JSON Objects from a File in Python Using json.loads() – Fixing Common Errors
A common use case in Python is reading an **array of JSON objects** (e.g., a list of user profiles, sensor readings, or product data) from a file. While Python’s `json` module simplifies this task, using `json.loads()` correctly can be tricky—especially for beginners.
🌐
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.