The error message is correct.

key = json.loads(response['password'])
print(key[0]),

The format of json is string. You need to convert the string of a json object to python dict before you can access it.

i.e.: loads(string) before info[key]

key = json.loads(response)['password']
print(key[0])
Answer from Cireo on Stack Overflow
🌐
Python Guides
pythonguides.com › json-data-in-python
How to Extract Values from a JSON Array in Python
April 27, 2026 - Learn to get values from a JSON array in Python. We cover the json module, list comprehensions, and handling nested data with real-world USA business examples.
Discussions

python - Accessing JSON elements - Stack Overflow
Yarkee has already explained @doniyor. It's because it's been converted to a dict using json.loads(). You're just trying to access the JSON directly... without transforming into anything readable by Python or using a module to do so. 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 More on stackoverflow.com
🌐 stackoverflow.com
Python accessing element inside array inside json - Stack Overflow
Can someone help me to access myapp from below json using python, please ? { "Data": { "Name": "myname", "AccountName": "test", "classic": [ { "cN... More on stackoverflow.com
🌐 stackoverflow.com
May 13, 2020
How to Access unlabeled JSON array elements in Python? - Stack Overflow
Working on a small project that returns JSON on API call. However, I seem to be unable to obtain the values from the string. I can print the JSON but cannot seem to obtain individual elements. I ... More on stackoverflow.com
🌐 stackoverflow.com
🌐
Zyte
zyte.com › home › blog › json parsing with python [practical guide]
JSON Parsing with Python [Practical Guide]
December 3, 2024 - 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.
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']]
    
🌐
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.
🌐
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
🌐
ReqBin
reqbin.com › code › python › g4nr6w3u › python-parse-json-example
How to parse a JSON with Python?
The JSON Decoder converts a JSON array to a Python list data type. You can access an element from a JSON array by its index in a Python object.
🌐
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.
🌐
pythontutorials
pythontutorials.net › blog › how-to-parse-json-to-get-all-values-of-a-specific-key-within-an-array
How to Parse JSON in Python to Get All Values of a Specific Key Within an Array? — pythontutorials.net
Use json.loads() to convert the string to a Python dictionary: ... Now, data is a dictionary with a key "users" pointing to the array. Access the "users" array, then loop through its objects to collect "name" values:
🌐
W3Schools
w3schools.com › python › python_json.asp
Python JSON
Arrays Code Challenge Python Iterators · Iterators Code Challenge Python Modules · Modules Code Challenge Python Dates · Dates Code Challenge Python Math · Math Code Challenge Python JSON · JSON Code Challenge Python RegEx · RegEx Code Challenge Python PIP Python Try...Except ·
🌐
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 Python by using the json module and then iterating through the array using a for loop.
🌐
GeeksforGeeks
geeksforgeeks.org › working-with-json-data-in-python
Working With JSON Data in Python | GeeksforGeeks
June 3, 2022 - The values in a JSON array must be separated by commas and enclosed in squares in brackets []. In this article, we will learn how we can loop through a JSON array in Python.
🌐
Oxylabs
oxylabs.io › blog › python-parse-json
Reading & Parsing JSON Data With Python: Tutorial
First, use the built-in json module to parse the JSON string into a Python dictionary or list. Once parsed, you can access individual elements using standard Python data access methods, such as dictionary keys for objects and indexes for arrays.
🌐
PYnative
pynative.com › home › python › json › python check if key exists in json and iterate the json array
Python Check if key exists in JSON and iterate the JSON array
May 14, 2021 - Let’s see how to use a default value if the value is not present for a key. As you know, the json.loads method converts JSON data into Python dict so we can use the get method of dict class to assign a default value to the key if the value is missing.
🌐
Stack Overflow
stackoverflow.com › questions › 62702059 › how-to-access-json-object-within-json-array-python
How to access JSON object within JSON array python? - Stack Overflow
July 3, 2020 - Copyx = json.dumps(hit, sort_keys=True, indent=4) # hit is the information returned (it is the comment before conversion)