LESSON · 1 OF 5

What is JSON

What is JSON

JSON is a text format for structured data. Almost every REST API speaks it, and plenty of config and state files use it too. Learning to move data in and out of JSON is a daily DevOps task.

The reason it feels natural in Python is that JSON maps directly onto types you already know.

The shapes

A JSON document is built from a small set of pieces:

  • An object, written with {}, becomes a Python dict.
  • An array, written with [], becomes a Python list.
  • A string in double quotes becomes a str.
  • A number becomes an int or float.
  • true and false become True and False.
  • null becomes None.

Here is a small JSON document:

json
{
  "service": "api",
  "port": 8080,
  "enabled": true,
  "tags": ["web", "public"]
}

Read into Python, that is a dict with four keys. data["port"] is the integer 8080, data["enabled"] is True, and data["tags"] is a list of two strings.

Why this matters

Because JSON becomes ordinary dicts and lists, you work with it using everything you already know: indexing, .get(), loops, comprehensions. There is no special JSON object to learn. You parse the text once, then it is just Python data.

The two nodes that follow show the two directions: turning JSON text into Python objects, and turning Python objects back into JSON text.

What this node introduces

  • JSON objects map to dicts and JSON arrays map to lists.
  • Strings, numbers, true/false, and null map to str, int or float, True/False, and None.
  • Once parsed, JSON is just dicts and lists you already know how to use.
Spin up a fresh environment and practice live.
python-devops · fresh machine · ready in under a minute