What JSON is
When your app asks an API a question, the answer comes back as text in a format called JSON (JavaScript Object Notation). It became the default because it's readable by humans and easy for programs to handle. You will see it constantly, so it's worth being able to read.
JSON is built from keys and values. A key is a label in quotes; a value is the data attached to it. Here is a real example describing one user:
{
"id": 42,
"name": "Ada Lovelace",
"email": "[email protected]",
"isAdmin": false,
"loginCount": 137,
"tags": ["beta", "early-access"],
"profile": {
"city": "London",
"avatarUrl": null
}
}
Read it like a form someone filled out. "name" is a field, "Ada Lovelace" is what they wrote in it. Two structures do all the work:
- An object is wrapped in curly braces
{ }. It's a bundle of key/value pairs — like one record. The whole example above is one object. - An array is wrapped in square brackets
[ ]. It's an ordered list of values. Above,"tags"holds an array of two strings.
Notice that "profile" is an object inside the object. JSON nests — a value can itself be an object or an array, as deep as needed. That's how a single response can describe a user, their address, and their last ten orders all at once.