What is JSON?

Understand the JSON format and how it maps to Python data structures

JSON and Python

JSON (JavaScript Object Notation) is a text format for representing structured data. It is used everywhere — API responses, configuration files, database exports, and web services all use JSON.

The best thing about JSON for Python developers: JSON maps directly to Python's built-in types.

JSONPython
{} objectdict
[] arraylist
"string"str
42 numberint
3.14 numberfloat
true / falseTrue / False
nullNone

JSON structure

JSON supports nesting — objects can contain arrays, arrays can contain objects.

{
  "user": {
    "name": "Alice",
    "scores": [95, 88, 92],
    "active": true
  }
}

Where JSON appears

  • API responses — nearly every web API returns JSON
  • Config files — settings for apps and tools
  • Data storage — structured records that don't fit in CSV

Python's json module

Python's built-in json module converts between JSON text and Python objects.

FunctionDirection
json.load(file)JSON file → Python object
json.loads(string)JSON string → Python object
json.dump(obj, file)Python object → JSON file
json.dumps(obj)Python object → JSON string

Next Chapter →