Your JSON is an array with a single object inside, so when you read it in you get a list with a dictionary inside. You can access your dictionary by accessing item 0 in the list, as shown below:

json1_data = json.loads(json1_str)[0]

Now you can access the data stored in datapoints just as you were expecting:

datapoints = json1_data['datapoints']

I have one more question if anyone can bite: I am trying to take the average of the first elements in these datapoints(i.e. datapoints[0][0]). Just to list them, I tried doing datapoints[0:5][0] but all I get is the first datapoint with both elements as opposed to wanting to get the first 5 datapoints containing only the first element. Is there a way to do this?

datapoints[0:5][0] doesn't do what you're expecting. datapoints[0:5] returns a new list slice containing just the first 5 elements, and then adding [0] on the end of it will take just the first element from that resulting list slice. What you need to use to get the result you want is a list comprehension:

[p[0] for p in datapoints[0:5]]

Here's a simple way to calculate the mean:

sum(p[0] for p in datapoints[0:5])/5. # Result is 35.8

If you're willing to install NumPy, then it's even easier:

import numpy
json1_file = open('json1')
json1_str = json1_file.read()
json1_data = json.loads(json1_str)[0]
datapoints = numpy.array(json1_data['datapoints'])
avg = datapoints[0:5,0].mean()
# avg is now 35.8

Using the , operator with the slicing syntax for NumPy's arrays has the behavior you were originally expecting with the list slices.

Answer from DaoWen on Stack Overflow
🌐
GeeksforGeeks
geeksforgeeks.org › python › convert-json-to-dictionary-in-python
Convert JSON to dictionary in Python - GeeksforGeeks
July 12, 2025 - Create a json string and store it in a variable 'json_string' after that we will convert the json string into dictionary by passing 'json_string' into json.loads() as argument and store the converted dictionary in 'json_dict'.
Top answer
1 of 6
365

Your JSON is an array with a single object inside, so when you read it in you get a list with a dictionary inside. You can access your dictionary by accessing item 0 in the list, as shown below:

json1_data = json.loads(json1_str)[0]

Now you can access the data stored in datapoints just as you were expecting:

datapoints = json1_data['datapoints']

I have one more question if anyone can bite: I am trying to take the average of the first elements in these datapoints(i.e. datapoints[0][0]). Just to list them, I tried doing datapoints[0:5][0] but all I get is the first datapoint with both elements as opposed to wanting to get the first 5 datapoints containing only the first element. Is there a way to do this?

datapoints[0:5][0] doesn't do what you're expecting. datapoints[0:5] returns a new list slice containing just the first 5 elements, and then adding [0] on the end of it will take just the first element from that resulting list slice. What you need to use to get the result you want is a list comprehension:

[p[0] for p in datapoints[0:5]]

Here's a simple way to calculate the mean:

sum(p[0] for p in datapoints[0:5])/5. # Result is 35.8

If you're willing to install NumPy, then it's even easier:

import numpy
json1_file = open('json1')
json1_str = json1_file.read()
json1_data = json.loads(json1_str)[0]
datapoints = numpy.array(json1_data['datapoints'])
avg = datapoints[0:5,0].mean()
# avg is now 35.8

Using the , operator with the slicing syntax for NumPy's arrays has the behavior you were originally expecting with the list slices.

2 of 6
31

Here is a simple snippet that read's in a json text file from a dictionary. Note that your json file must follow the json standard, so it has to have " double quotes rather then ' single quotes.

Your JSON dump.txt File:

{"test":"1", "test2":123}

Python Script:

import json
with open('/your/path/to/a/dict/dump.txt') as handle:
    dictdump = json.loads(handle.read())
🌐
Reddit
reddit.com › r/learnpython › convert json list to dictionary
r/learnpython on Reddit: convert JSON list to dictionary
January 13, 2024 -

I must first preface this with the fact that I’m extremely new to python. Like just started learning it a little over a week ago.
I have been racking my brain over how to convert a json object I opened and loaded into a dictionary from a list so I can use the get() function nested within a for loop to do a student ID comparison from another json file (key name in that file is just ID).
Below is the command I’m trying to load the json file:
With open(‘file.json’) as x: object=json.load(x)
When I print(type(object)), it shows up as class list.
Here’s a sample of what the json looks like:
[

{

“Name”: “Steel”,

“StudentID”: 3458274

“Tuition”: 24.99

},

{

“Name”: “Joe”,

“StudentID”: 5927592

“Tuition”: 14.99

}

]
HELP! Thank you!

🌐
Medium
medium.com › @jimitdoshi639 › parse-content-in-json-file-into-a-dictionary-in-python-a-fun-and-informative-guide-88c169561550
Parse content in JSON file into a dictionary in Python: A fun and informative guide | by Jimit Doshi | Medium
May 4, 2024 - Accessing the Data: Now you can access the data in the dictionary as you would with any other dictionary in Python. ... Replace 'key' with the specific key you want to access in your JSON data. Putting it all together, here’s a complete example: ... # Open the JSON file with open('data.json', 'r') as file: data = file.read()# Parse JSON data into a dictionary parsed_data = json.loads(data)# Accessing the data print(parsed_data['key'])
🌐
Index.dev
index.dev › blog › convert-json-to-dictionary-python
How to Convert JSON to a Python Dictionary: Step-by-Step Guide
The simplest approach to translate a JSON-formatted text into a Python dictionary is with json.loads().
🌐
GeeksforGeeks
geeksforgeeks.org › python › json-loads-in-python
json.loads() in Python - GeeksforGeeks
Explanation: json.loads(s) parses the JSON string s and converts it into a Python dict.
Published   June 16, 2020
🌐
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
Find elsewhere
🌐
Python Examples
pythonexamples.org › python-json-to-dict
Python JSON to Dictionary
To convert Python JSON string to Dictionary, use json.loads() function.
🌐
W3Schools
w3schools.com › python › python_json.asp
Python JSON
Python has a built-in package called json, which can be used to work with JSON data. ... If you have a JSON string, you can parse it by using the json.loads() method. The result will be a Python dictionary.
🌐
iO Flood
ioflood.com › blog › json-loads
json.loads() Python Function | Convert JSON to dict
February 1, 2024 - In this example, we have a JSON string json_string that represents a person named John who is 30 years old. The json.loads function is used to convert this JSON string into a Python dictionary, which is then printed out.
🌐
Spark By {Examples}
sparkbyexamples.com › home › python › convert json to dictionary in python
Convert JSON to Dictionary in Python - Spark By {Examples}
May 31, 2024 - The json.loads() function parses the JSON string and converts it into a Python dictionary (python_dict).
🌐
Python
docs.python.org › 3 › library › json.html
JSON encoder and decoder — Python 3.14.3 documentation
cls (a JSONDecoder subclass) – If set, a custom JSON decoder. Additional keyword arguments to load() will be passed to the constructor of cls. If None (the default), JSONDecoder is used. object_hook (callable | None) – If set, a function that is called with the result of any JSON object literal decoded (a dict).
🌐
NetworkAcademy
networkacademy.io › learning path: ccna automation (200-901) ccnaauto › data formats and data models › parsing json with python
Parsing JSON with Python | NetworkAcademy.IO
There are a few python methods used to load json data: load(): This method loads data from a JSON file into a python dictionary. loads(): This method loads data from a JSON variable into a python dictionary. dump(): This method loads data from the python dictionary to the JSON file.
🌐
PythonForBeginners.com
pythonforbeginners.com › home › load json into a python dictionary
Load JSON into a Python Dictionary - PythonForBeginners.com
February 8, 2023 - You can observe that the JSON format is almost similar to the format of a python dictionary. To load a json string into a python dictionary, you can use the loads() method defined in the json module.
🌐
Reddit
reddit.com › r/learnpython › convert json array to dictionary
r/learnpython on Reddit: Convert JSON array to Dictionary
March 22, 2022 -

I have a JSON array file that I want to convert to a dictionary. The file has only one pair of square brackets [] with a dictionary of sub dictionaries inside it. print(len(dict)) returns 14. I want to simply convert the file to a dict but using json.loads() creates a list and using json.loads(filename)[0] to get that sole large item of nested dictionaries inside the json array only returns the first dictionary object and not the entire 14.

I want to know if there’s another way of doing this besides a dictionary comprehension which I found, but don’t necessarily understand. Thanks.

🌐
MLJAR
mljar.com › docs › python-read-json-from-file
Read JSON file to dict in Python
Load JSON file to dict. Print dict object with indentation. It is a good practice to check if file exists before reading it. There is Check if file exists recipe available. Code recipes from Python cookbook.
🌐
Appdividend
appdividend.com › python-json-to-dict
How to Convert JSON to Dictionary in Python
November 24, 2025 - import json # Empty JSON object json_string = '{}' dictionary = json.loads(json_string) print(dictionary) # Output: {} # JSON with null json_string = '{"name": null, "age": 30}' dictionary = json.loads(json_string) print(dictionary['name']) # Output: None · JSON data often contains special characters in real-life scenarios. Python handles special and unicode characters automatically if they are in the input json data.
🌐
AskPython
askpython.com › home › how to convert json to a dictionary in python?
How to convert JSON to a dictionary in Python? - AskPython
February 16, 2023 - Now, let’s convert this JSON ... the sample JSON file which we created above. Convert the file data into dictionary using json.load() function....