JSON (JavaScript Object Notation) is a plain-text format for structured data: objects in curly brackets { } hold "key": value pairs, arrays in square brackets [ ] hold lists. Most web services send their answers as JSON, often as one long line that nobody can read. The formatter turns that line into an indented tree.
What it does
Formats JSON with indentation so nested objects and arrays become readable. It formats as you type.
Says whether the text is valid JSON, and where it breaks if it is not.
Minifies it back to one line.
Lets you choose the indentation: 2 spaces, 4 spaces or a tab.
Copies the result, or downloads it as a file called
formatted.json.Has a Sample button that loads a short example, and Clear to start again.
It runs in the browser: what you paste is not uploaded, and no account is needed.
The error message comes from the browser itself, so its wording differs between Chrome, Firefox and Safari. Most name the place as a line and column or as a character position, for example "Expected double-quoted property name in JSON at position 16 (line 1 column 17)".
The rules it checks
The tool checks strict JSON, the standard every web service relies on. The five rules learners break most often:
Keys and text values need double quotes:
"name": "Anna", nevername: 'Anna'.No comma after the last item of an object or array:
[1, 2, 3], not[1, 2, 3,].true,falseandnullare written in lower case.No comments.
// noteis not allowed anywhere, even though some configuration files accept it.Numbers are plain: no leading zeros (
7, not007), no.5without the zero, noNaN.
A single value such as 42 or "hello" is valid JSON on its own, and so is any text with accents or other alphabets, such as "city": "Köln".
A worked example
This snippet has three errors. Paste it into the tool and fix them one at a time; the message changes as each one is fixed.
{
"company": "Northwind Traders",
"city": 'Hamburg',
"active": True,
"contacts": ["anna.berger@northwind.example", "sam.reed@northwind.example",]
}Solution
'Hamburg'uses single quotes. Write"Hamburg".Truehas a capital T. Writetrue.There is a comma after the last address in the array. Delete it.
{
"company": "Northwind Traders",
"city": "Hamburg",
"active": true,
"contacts": ["anna.berger@northwind.example", "sam.reed@northwind.example"]
}Minified, the fixed version is one line of 136 characters instead of six lines.
What formatting changes, and what it does not
Formatting and minifying only move spaces and line breaks. Keys keep their order and values keep their meaning. A few details do change, because the text is read and written again:
If a key appears twice in one object, only the last value is kept.
1.0becomes1and1e3becomes1000: the same number, written differently.Very long whole numbers (more than about 15 digits, such as some ID numbers) lose their last digits. Real services send such IDs as text in quotes for exactly this reason.
Common mistakes
Pasting a JavaScript object from code instead of JSON. JavaScript allows single quotes and keys without quotes; JSON does not.
Copying "smart" curly quotes from a word processor.
“name”is not"name".Pasting two JSON objects one after the other. That is two documents; wrap them in an array:
[{...}, {...}].Looking for the error only at the reported position. The real mistake is often just before it, such as a missing comma at the end of the previous line.
Ideas for class
Paste the snippets from the JSON basics exercise and let the tool confirm each answer.
Open a public API response (for example an open data portal) and let learners find one value in the formatted result.
Error hunt: each learner writes a valid snippet about themselves (name, hobbies as an array, one nested object), then breaks it with one of the five errors above. A partner finds the error with the tool.
Format and minify: compare the length of the same data formatted and minified. Why do web services send the minified version?
Valid or not?
1.Is { "price": 4.90, "currency": "EUR" } valid JSON?
2.Is { 'price': 4.90 } valid JSON?
3.Is ["red", "green", "blue",] valid JSON?
4.Is { "active": null } valid JSON?
The tool is free to use. This description is licensed under CC BY 4.0.
