JSON

JSON (JavaScript Object Notation) is a lightweight, text-based data format used to store and exchange structured data in a simple, readable way.

  • Uses key–value pairs and arrays
  • Easy for humans to read and machines to parse
  • Commonly used in APIs, configuration files, and data exchange
1
2
3
4
5
{
  "name": "robot",
  "enabled": true,
  "count": 3
}
simple.py
1
2
3
4
5
6
7
8
9
import json
import pprint

try:
    with open("simple.json") as f:
        data = json.load(f)
        pprint.pprint(data)
except json.JSONDecodeError as e:
    print("Invalid JSON:", e)