Skip to content

Python read JSON file into dict

  • by

Use the json module loads method to read JSON files into dict in Python. JSON loads create a new dictionary with the key-value pairs of the JSON string and it returns this new dictionary.

json.loads(data_JSON)

Python read JSON files into dict example

Simple example code load JSON from a File and Parse Dumps. We have simple.json which contains json data.

import json

with open('data.json') as f_in:
res = json.load(f_in)

print(json.dumps(res, indent=3))
print(type(res))

Output:

Python read JSON file into dict

This table presented corresponding Python values and data types.

JSONPython
objectdict
arraylist
stringstr
number (int)int
number (real)float
trueTrue
falseFalse
nullNone

json.dumps(client) creates and returns a string with all the key-value pairs of the dictionary in JSON format.

Do comment if you have any doubts or suggestions on this Python JSON file topic.

Note: IDE: PyCharm 2021.3.3 (Community Edition)

Windows 10

Python 3.10.1

All Python Examples are in Python 3, so Maybe its different from python 2 or upgraded versions.

Leave a Reply

Discover more from Tutorial

Subscribe now to keep reading and get access to the full archive.

Continue reading