home..
python-json-notes
python
Intro
- JSON - JavaScript Object Notation
- lightweight data format
JSON to python object
json.load()
-> read JSON from file and convert to python object
with open('data.json', 'r') as file:
data = json.load(file)
json.loads()
-> JSON string to python object
json_string = '{"name":"John", "age":"32"}'
data = json.loads(json_string)
python object to JSON
json.dump()
-> convert object to JSON and write to file
data = '{"name":"John", "age":"32"}'
with open('data.json', 'w') as f:
json.dump(data, f, indent=4)
json.dumps()
-> convert object to JSON string
© 2025 Jithendra Yenugula