The universal language of data
Programs constantly need to exchange data: script → website, server → app, API → your code. Exchange needs a common format, and in the modern world that's JSON (JavaScript Object Notation) — a text notation for the arrays and objects from earlier lessons.
It looks familiar because the syntax grew out of JavaScript:
{
"client": "Anna",
"orders": [
{ "id": 1, "total": 5600, "paid": true },
{ "id": 2, "total": 1200, "paid": false }
],
"vip": true
}
The rules are stricter than in JS: keys only in double quotes, no comments, no comma after the last element. Values: strings, numbers, booleans (true/false), null, arrays, objects — and that's all.
If you took the AI course, you saw JSON in action: the Claude API accepts and returns JSON, tool configs are written in JSON, your monitoring script pushes JSON around. It's literally the blood of automation.
Parsing and serialization
JSON is text. To work with the data, you turn the text into the language's structures (parsing) and back (serialization):
Four operations that cover everything: JSON.parse / json.loads — text into a structure, JSON.stringify / json.dumps — structure into text. In Python the json module is imported first — meet import, more on it in the pro modules.
A real example: parsing an API response
This is what typical work with data from the outside world looks like — JSON arrived, we parsed it, we walked through it with a loop:
Recognize the construct? An array of objects + a loop + an accumulator from earlier lessons. JSON added no new concepts — only a packaging format.
Broken JSON
JSON.parse on a malformed string fails with an error — an extra comma, single quotes, truncated text. The rule for real scripts: parsing external data is wrapped in error handling (module 4), because the outside world sends garbage regularly.
A quick eyeball check: online JSON validators, or just ask Claude — "is this JSON valid? where's the error?"
Key takeaways
- JSON is a text exchange format: objects and arrays with strict notation rules.
- Parsing:
JSON.parse/json.loads; serialization:JSON.stringify/json.dumps. - After parsing, all the familiar patterns work: loop, fields, accumulator.
- External JSON can be broken — in real scripts, parsing is guarded with error handling.