json.dumps() converts a dictionary to str object, not a json(dict) object! So you have to load your str into a dict to use it by using json.loads() method

See json.dumps() as a save method and json.loads() as a retrieve method.

This is the code sample which might help you understand it more:

import json

r = {'is_claimed': 'True', 'rating': 3.5}
r = json.dumps(r)
loaded_r = json.loads(r)
loaded_r['rating'] #Output 3.5
type(r) #Output str
type(loaded_r) #Output dict
Answer from Iman Mirzadeh on Stack Overflow
๐ŸŒ
GeeksforGeeks
geeksforgeeks.org โ€บ python โ€บ convert-json-to-dictionary-in-python
Convert JSON to dictionary in Python - GeeksforGeeks
July 12, 2025 - In the below code, firstly we open the "data.json" file using file handling in Python and then convert the file to Python object using the json.load() method we have also print the type of data after conversion and print the dictionary.
๐ŸŒ
Spark By {Examples}
sparkbyexamples.com โ€บ home โ€บ python โ€บ convert python dictionary to json
Convert Python Dictionary to JSON - Spark By {Examples}
May 31, 2024 - The data in the JSON is made up of the form of key/value pairs and they can be enclosed with {}. Look wise it is similar to a Python dictionary.
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())
๐ŸŒ
Educative
educative.io โ€บ answers โ€บ how-to-convert-json-to-dictionary-in-python
How to convert JSON to dictionary in Python?
Line 1: Import the json module in Python. Line 3: Assign a JSON string to userJSON. The string contains fname and lname along with the values. Line 4: Print the type of the userJSON string. It will show <class 'str'>. Line 8: Assign a dictionary object to user variable by sending userJSON as a parameter to the json.loads() conversion method.
๐ŸŒ
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!

๐ŸŒ
Index.dev
index.dev โ€บ blog โ€บ convert-json-to-dictionary-python
How to Convert JSON to a Python Dictionary: Step-by-Step Guide
This module lets you translate JSON texts and files into Python objects including dictionaries by parsing them. The simplest approach to translate a JSON-formatted text into a Python dictionary is with json.loads().
Find elsewhere
๐ŸŒ
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.
๐ŸŒ
Oregon State University
blogs.oregonstate.edu โ€บ logicbot โ€บ 2022 โ€บ 04 โ€บ 08 โ€บ saving-a-dictionary-with-json
Saving a dictionary with JSON โ€“ Logic_bot
I have to say that I am a little ... with it. Useless. Thatโ€™s where this little one liner comes in. json.loads() turns JSON formatted data back into a dictionary that you can reference normally....
๐ŸŒ
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 - Letโ€™s discuss how to convert the JSON string object to a Dictionary in python. From JSON string, we can convert it to a dictionary using the json.loads() method. Suppose you have a JSON file, then loads() will not work.
๐ŸŒ
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 - &lt;class 'dict'> Key: Linux Value: ... how to read a JSON file and then convert it into a Python dictionary using json.load() function....
๐ŸŒ
Jsontotable
jsontotable.org โ€บ blog โ€บ python โ€บ python-json-to-dict
Python JSON to Dict - Convert JSON String to Dictionary (2025) | JSON to Table Converter
Python's built-in json module makes this conversion straightforward with two main functions. This guide shows you exactly how to convert JSON to dictionaries in Python, with practical examples for JSON strings, files, nested objects, and error handling.
๐ŸŒ
Reddit
reddit.com โ€บ r/learnpython โ€บ what's the real difference between a dict and a json object (coming from js background)
r/learnpython on Reddit: What's the real difference between a dict and a JSON object (coming from JS background)
October 9, 2022 -

Hello all,

I'm going through 100 Days of Python and reading "Introducing Python" by O'Reilly one thing that bothers me is the dict (insert funny joke). But seriously, what's the difference between a dict and a JSON object in JavaScript? Is there really any difference or should I just treat them as the same?

Kind regards

Top answer
1 of 4
15
JSON is a file format that uses a key - value pair syntax. Keys can only be unicode strings surrounded by doubel quotes, like "name". Values can be: Only certain number formats like 5, -5, 5.5, 1.0E+5 The values true, false, and null Unicode strings in double quotes, like "hello" Array: an ordered, comma separated list of any valid value type Object: a collection of key-value pairs that itself confirms to the JSON syntax ---------------------------------- A Python dict is an object that can have any hashable object as a key. Itโ€™s more flexible. A number, a decimal, a string, a tuple, etc can be a key. A Python dict value has no limits (that I know of). It can be any Python object. A string, a number, a function, another dict, a whole entire module. You name it. ---------------------------------- What makes JSON so powerful is that it's an agreed upon format. No matter if you're using Python, Java, PHP, or Ruby, if someone sends your app data in the JSON format, the shape is predictable so your programming language of choice will be able to parse it. How Java, Python, JavaScript, etc. decide to parse JSON into an object will be a little different depending on the language. Python can decode a string or file that confirms to the JSON format into a Python dict. ---------------------------------- One nuance that I wanted to point out is even though JSON stands for "JavaScript Object Notation", it is NOT JavaScript. JSON is a file format/data exchange format. Someone said "So 1 and 1.0 are two different values in Python, while in JSON, they would be the same." That's not quite true. JSON is only a format. 1 and 1.0 in a json file are no more "the same" as 1 and 1.0 are in a txt file. What that person probably meant is that 1 and 1.0 are the same in JavaScript, but that's besides the point because it's important to remember that JSON is NOT JavaScript, it's a format.
2 of 4
4
The most obvious difference is that JSON objects have to have strings as keys, and JSON values as values (which can only be null, true, false, numbers, strings, arrays or objects). Python dictionaries can have any Python object as either a key or a value. Also they are just different languages and there are subtle differences in the way they model data even if they are roughly equivalent a lot of the time. For example, Python distinguishes ints from floats, whereas in JSON there are only "numbers". So 1 and 1.0 are two different values in Python, while in JSON, they would be the same.
๐ŸŒ
Json-to
json-to.com โ€บ json-python
Free JSON to Python Converter | Convert JSON to Python Dict Online
Convert JSON to Python dictionaries instantly! Our free online converter transforms JSON data into Python-compatible objects. Perfect for data science, web scraping, and Python development.
๐ŸŒ
GeeksforGeeks
geeksforgeeks.org โ€บ python โ€บ how-to-convert-python-dictionary-to-json
How To Convert Python Dictionary To JSON? - GeeksforGeeks
July 12, 2025 - In Python, a dictionary stores information using key-value pairs. But if we want to save this data to a file, share it with others, or send it over the internet then we need to convert it into a format that computers can easily understand. JSON (JavaScript Object Notation) is a simple format ...
๐ŸŒ
CodeShack
codeshack.io โ€บ home โ€บ tools โ€บ json to python converter
JSON to Python Converter - Online JSON Object to Dict Tool
Instantly convert JSON to Python dictionaries online. Our free tool translates JSON arrays and objects into correctly formatted Python code with True, False, and None support.