Part 3 · Code and data
JSON
How computers send data to each other.
What it is
When two programs exchange data, they usually use JSON. It is plain text with names and values, such as {"type": "cat", "age": 4}. Curly brackets { } hold one thing. Square brackets [ ] hold a list. People can read it too, so it is a good way to see what data a system sends.
Try it
Describe your cat to a computer. Try these steps:
- Change the values. The check under the editor says if the JSON is valid, and shows the data as a tree.
- Tap “Add a list”:
"traits": ["hungry", "loud"]appears. - Tap “Add a second cat”: the two cats go into a list
[ … ]. - Tap “Make a typical mistake”: a comma at the end. The check turns red and shows the line. Fix it.
- Switch the view to “Table” and “XML”: the same cats in other formats.
In a meeting
Ask for one sample of the data, in JSON. One real example shows what the other system sends and what is missing, before anyone writes code.
Where it is on the journey
One visit to a website, in 8 steps. The lit steps are where JSON works.
The request goes out
- Youtype an address
- Browsersends the request
- ISPcarries it on the internet
- Name serverfinds the IP address
- Server / web servergets the request, sends the answer (this term)sends { JSON }
The answer comes back
- Code (PHP)builds the answer
- Databasegives the data
- Browsergets the answer and shows the page (this term)shows the data
Many pages load first, then ask the server for data. The server answers in JSON, and the page shows that data.