What Is JSON? A Plain-English Introduction
JSON is the most common way apps and websites send information to each other. If you have ever looked at a settings file, an API response or exported data from an app, you have probably seen it. It is simpler than it looks.
JSON in one sentence
JSON (JavaScript Object Notation) is a way of writing information as labelled values, so both people and computers can read it. Despite the name, almost every programming language understands it, not only JavaScript.
The building blocks
| Type | Example | Meaning |
|---|---|---|
| Text (string) | "Amina" | Words, always in double quotes |
| Number | 42 or 3.5 | No quotes |
| True / false | true | Yes-or-no values, lowercase |
| Nothing | null | An empty value |
| List (array) | ["tea", "cake"] | Several values in order, in square brackets |
| Object | {"name": "Amina"} | Labelled values, in curly brackets |
A real example
An online shop might describe an order like this: {"order": 1052, "paid": true, "items": ["green tea", "teapot"], "customer": {"name": "Amina", "city": "Oran"}}. Read it aloud and it almost makes sense as English: order number 1052, paid, two items, and a customer called Amina who lives in Oran.
Paste that line into the JSON Formatter and press Beautify to see it laid out over several lines, with the customer’s details neatly indented inside.
The five mistakes everyone makes
- A comma after the last item: ["tea", "cake",] is not allowed.
- Single quotes: {'name': 'Amina'} must use double quotes.
- Labels without quotes: {name: "Amina"} needs quotes around name.
- Comments: // notes are not allowed in standard JSON.
- Capital letters in True, False or Null: they must be lowercase.
JSON and APIs
When a weather app shows tomorrow’s forecast, it asks a server for the data, and the server usually answers in JSON. Developers read these answers all day, which is why a formatter that makes JSON readable and points out mistakes is one of the most used developer tools on the web.