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
🌐
GeeksforGeeks
geeksforgeeks.org › python › json-loads-in-python
json.loads() in Python - GeeksforGeeks
Example 1: This example converts a JSON string containing user details into a Python dictionary. ... Example 2: This example shows how a JSON array is converted into a Python list.
Published: January 13, 2026
🌐
Python Examples
pythonexamples.org › python-json-to-list
Python JSON to List
After loading the JSON string to list, we shall print the value for key "b". import json jsonStr = '[{"a":1, "b":2}, {"c":3, "d":4}]' aList = json.loads(jsonStr) print(aList[0]['b']) ... In this example, we will take a JSON String with Array of Arrays and convert it to Python List of Lists.
🌐
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 - ... import json json_string = """ { "Student": { "ID" : "3", "name": "kelvin", "Group": "A", "Program" : "BSSE" } } """ data = json.loads(json_string) print(data) ... The structure of JSON arrays is identical to that of Python bracketed lists.
🌐
W3Schools
w3schools.com › python › python_json.asp
Python JSON
import json # some JSON: x = '{ "name":"John", "age":30, "city":"New York"}' # parse x: y = json.loads(x) # the result is a Python dictionary: print(y["age"]) Try it Yourself »
🌐
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 - For example, You want to retrieve the project name from the developer info JSON array to get to know on which project he/she is working.
🌐
Python
docs.python.org › 3 › library › json.html
JSON encoder and decoder — Python 3.14.7 documentation
Identical to load(), but instead of a file-like object, deserialize s (a str, bytes or bytearray instance containing a JSON document) to a Python object using this conversion table.
🌐
GeeksforGeeks
geeksforgeeks.org › loop-through-a-json-array-in-python
Loop through a JSON array in Python - GeeksforGeeks
March 28, 2024 - You can loop through a JSON array ... 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....
🌐
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
Objects within the array follow JSON object rules (key-value pairs with double quotes for keys). The json module in Python provides two primary methods for parsing JSON: json.load(file_object): Parses JSON directly from a file-like object (e.g., an open file).
Find elsewhere
🌐
Qlik Community
community.qlik.com › t5 › Member-Articles › Parsing-JSON-Array-Homogeneous-Objects › ta-p › 2535153
Parsing: JSON Array (Homogeneous Objects) - Qlik Community - 2535153
November 4, 2025 - WildDataFrontier.qvf that is attached, upload it to your environment and open the load script. { Notice there are multiple sections. Each of them will pertain to a separate article and for this article the section named " 3 - JSON Array: Homogeneous Objects" is the one you want to have at the top of your script for this post.
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 › python-json-to-list
Python Json To List - GeeksforGeeks
April 18, 2026 - The json.loads() method parses a JSON-formatted string into a Python object. 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 arr.
🌐
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 - If you load this JSON in your JavaScript program as a string, you can parse it into a normal object and then access the data inside it using the same dot/bracket notation we looked at in the JavaScript object basics article. For example: ... First, we have the variable name — superHeroes. Inside that, we want to access the members property, so we use .members. members contains an array populated by objects.
🌐
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 - For example, if you forget to specify the name of the field manufacturer for one of the JSON array elements: >> st_cars = '[{"Tesla Inc.", "model": "Tesla S", "engineType": "elecrical", "horsePower": 362}, {"manufacturer": "Tesla Inc.", "model": "Tesla 3 ","engineType": "elecrical"," horsePower": 346}]' >> js_cars = json.loads(st_cars)
🌐
DataCamp
datacamp.com › tutorial › json-data-python
Python JSON Data: A Guide With Examples | DataCamp
December 3, 2024 - In this example, we have a JSON object that represents a person. The object has several properties: name, age, email, and is_employee. The hobbies property is an array that contains three strings.
🌐
Real Python
realpython.com › python-json
Working With JSON Data in Python – Real Python
August 20, 2025 - When you serialize a Python tuple, it becomes a JSON array. When you load JSON, a JSON array correctly deserializes into a list because Python has no way of knowing that you want the array to be a tuple.
🌐
Processing
processing.org › reference › loadJSONArray_.html
loadJSONArray() / Reference
January 1, 2021 - /* [ { "id": 0, "species": "Capra hircus", "name": "Goat" }, { "id": 1, "species": "Panthera pardus", "name": "Leopard" }, { "id": 2, "species": "Equus zebra", "name": "Zebra" } ] */ JSONArray values; void setup() { values = loadJSONArray("data.json"); for (int i = 0; i < values.size(); i++) { JSONObject animal = values.getJSONObject(i); int id = animal.getInt("id"); String species = animal.getString("species"); String name = animal.getString("name"); println(id + ", " + species + ", " + name); } } // Sketch prints: // 0, Capra hircus, Goat // 1, Panthera pardus, Leopard // 2, Equus zebra, Zebra
🌐
Python Guides
pythonguides.com › json-data-in-python
How to Extract Values from a JSON Array in Python
April 27, 2026 - JSON vs. Dictionary: Remember that json_data is a string. You cannot loop through it until you use json.loads().
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?