What JSON is
JSON (JavaScript Object Notation) is a text format for structured data, used by most web APIs and configuration files. It has only six kinds of value: objects, arrays, strings, numbers, true or false, and null.
{
"name": "SigapTek",
"tags": ["tools", "guides"],
"active": true,
"version": 1.5,
"owner": null
}
The syntax rules
- Objects use curly braces with
"key": valuepairs separated by commas. - Arrays use square brackets with values separated by commas.
- Keys and strings must use double quotes. Single quotes are invalid.
- No trailing comma after the last item.
- No comments.
- Numbers have no leading zeros or leading plus sign, and no
NaNorInfinity. - Special characters in strings need escapes, such as
\nfor a new line and\"for a quote.
The errors you will meet most
| Error | Cause | Fix |
|---|---|---|
| Unexpected token or character | Single quotes, unquoted keys, or a stray character | Use double quotes around all keys and strings |
| Trailing comma | A comma before } or ] | Remove the last comma |
| Expected a comma | A missing comma between items | Add the comma |
| Unexpected end of input | A missing closing bracket or brace | Add the closing character |
| Unescaped control character | A raw line break inside a string | Replace it with \n |
| Comments not allowed | // or /* */ in the text | Remove them, or use a JSON5 or JSONC parser if your tool supports it |
Format, validate, minify
- Format (pretty print) adds indentation so humans can read nested data.
- Validate checks the syntax and tells you where it breaks.
- Minify removes optional whitespace to reduce size for transfer.
All three keep the data the same. Paste your text into the JSON Formatter, Validator & Minifier to do them in your browser. It shows the line and column of the first error and highlights the exact spot.
JSON is not a JavaScript object
A JavaScript object literal may have unquoted keys, single quotes, and trailing commas. JSON may not. To produce valid JSON from code, let the language do it:
JSON.stringify(obj, null, 2) // JavaScript
json.dumps(obj, indent=2) // Python
json_encode($arr, JSON_PRETTY_PRINT) // PHP
Large numbers and precision
Many parsers convert numbers to floating point, which cannot represent integers above 2^53 exactly. If an ID such as 12345678901234567890 matters, send it as a string.
Validate the structure too
Valid syntax does not mean valid data. To check that required fields and types are present, use a JSON Schema validator in your code.
FAQ
Why does my JSON work in my code but fail in a validator?
The code probably accepts JavaScript object syntax. A JSON validator is strict.
Can JSON have comments?
Not in the standard. Some tools accept JSONC or JSON5, but they are different formats.
Is it safe to paste private JSON into an online tool?
Only if the tool processes it locally. The JSON Formatter runs in your browser and does not upload your input. Still avoid pasting live secrets anywhere.