JSON is the standard format for web data exchange. Learn its structure and how to read/write it in Python.
What JSON Is and How to Read It with Python

JSON is a lightweight text format used to represent and exchange structured data. It is standard in APIs, configuration files, and many backend workflows.

Running the script

Save your example as json_example.py and run it from terminal.

JSON structure

JSON uses objects {} and arrays [] with values such as strings, numbers, booleans, and null.

Reading from file

Use json.load() to read JSON data from files into Python dictionaries/lists.

Writing to file

Use json.dump() to serialize Python objects into JSON, optionally with indentation.

loads and dumps

json.loads() parses JSON strings, while json.dumps() converts Python objects into JSON strings.

import json
with open("input.json", "r", encoding="utf-8") as f:
    data = json.load(f)