JSON Formatter and Validator: Fix Common JSON Errors Fast
Format and validate JSON privately, understand errors like trailing commas and single quotes, and format JSON in VS Code, Notepad++ or the terminal.
A JSON formatter and validator does two jobs: it checks that your JSON is valid, and it re-indents it so you can read it. Paste your JSON into our JSON formatter and choose 2 spaces, 4 spaces or tabs, or Minify to squash it onto one line. If the JSON is invalid, you see the parser's error message instead, which usually points to where the problem is. Everything runs in your browser, so API keys and customer data in the JSON never leave your machine.
Most JSON errors come from a handful of mistakes. Here they are, followed by how to format JSON in VS Code, Notepad++ and the terminal.
How to use the JSON formatter
- Paste your JSON into the box.
- Pick an indent: 2 spaces, 4 spaces, Tabs or Minify.
- If it is valid, the formatted result appears. Click Copy result or Download .txt.
- If it is invalid, you see a message starting with "Invalid JSON" followed by the browser's description of the error.
The exact wording of error messages depends on your browser, but most include a position (a character offset, and in some browsers a line and column). Look just before that point for the mistake.
Common JSON errors and how to fix them
| Error | Invalid | Valid |
|---|---|---|
| Trailing comma | {"a": 1, "b": 2,} |
{"a": 1, "b": 2} |
| Single quotes | {'a': 'x'} |
{"a": "x"} |
| Unquoted key | {a: 1} |
{"a": 1} |
| Missing comma | {"a": 1 "b": 2} |
{"a": 1, "b": 2} |
| Comment | {"a": 1 // note} |
{"a": 1} |
| Undefined or NaN | {"a": undefined} |
{"a": null} |
| Leading zero | {"pin": 0110} |
{"pin": "0110"} |
| Line break inside a string | "line one + newline + line two" |
"line one\nline two" |
| Curly quotes | {“a”: 1} |
{"a": 1} |
Trailing commas
The most common error by far. JavaScript object literals allow a comma after the last item, so people copy that habit into JSON. Standard JSON does not allow it. Delete the comma before the closing } or ].
Single quotes and unquoted keys
JSON is stricter than JavaScript: every key must be a string in double quotes, and so must every string value. Python's print(dict) output uses single quotes, which is why pasting a printed Python dictionary fails. Use json.dumps(data) in Python to get real JSON.
Comments
JSON has no comments. Some tools accept "JSON with comments" (VS Code's settings.json is one), but JSON.parse and most APIs do not. Remove // and /* */ comments, or put notes in a field like "_comment".
Special values
undefined, NaN, Infinity and functions are not JSON. Use null, a number, or a string.
Curly quotes from Word or WhatsApp
If you copied JSON from a document or chat, the straight quotes " may have been turned into curly quotes “ ”. They look similar but are different characters. Retype them, or use a code editor's find and replace.
Strings with line breaks and backslashes
A literal line break inside a string is invalid; write \n instead. A single backslash must be doubled: a Windows path is "C:\\Users\\asha".
Things a formatter changes that you might not expect
Our formatter parses your JSON into data and writes it back out. That means:
- Very large integers lose precision. JavaScript numbers are exact only up to 9,007,199,254,740,991. An ID like
12345678901234567890is rewritten as a slightly different number. If your JSON has huge numeric IDs, check them after formatting, or keep them as strings in your data. - Duplicate keys are merged. If an object has the same key twice, only the last value survives.
- Number formatting is normalised, for example
1.0becomes1and1e3becomes1000.
Key order and string contents are kept as they are.
How to format JSON in VS Code
- Open the file. Check the bottom-right corner says JSON; if not, click the language name and choose JSON.
- Press Shift+Alt+F (Windows), Shift+Option+F (Mac) or Ctrl+Shift+I (Linux). Or right-click and choose Format Document.
- To format on every save, turn on Editor: Format On Save in Settings.
VS Code underlines JSON errors in red and lists them in the Problems panel.
How to format JSON in Notepad++
Notepad++ does not format JSON out of the box. Install a plugin through Plugins > Plugins Admin, such as JSON Viewer or JSTool, then use its Format JSON command from the Plugins menu.
Format JSON on the command line
- Python:
python -m json.tool data.jsonprints formatted JSON (usepython3on systems wherepythonis not Python 3). - jq:
jq . data.jsonformats;jq -c . data.jsonminifies. - JavaScript:
JSON.stringify(obj, null, 2)gives 2-space indented JSON;JSON.stringify(obj)gives minified JSON.
Minify vs beautify
Beautified JSON is for people: indented, one item per line, easy to read and diff. Minified JSON is for machines: no whitespace, smallest size, best for sending over a network or storing in a single line. Both contain exactly the same data.
JSON inside other encodings
JSON often arrives wrapped in another layer:
- Base64, for example the middle part of a JWT token or a data blob in a config. Decode it with Base64 encode/decode, then paste the result here. Our guide on Base64 encoding explains how it works.
- URL-encoded, in a query string like
?data=%7B%22id%22%3A1%7D. Decode it with URL encode/decode first.
Common mistakes
- Pasting secrets into server-side formatters. Use one that runs locally.
- Fixing the first error and assuming you are done. Re-validate; there may be more.
- Editing minified JSON by hand. Beautify it, edit, then minify again.
- Using JSON for config with comments and then feeding it to a strict parser.
Questions
How do I format JSON in VS Code?
Open the .json file and press Shift+Alt+F on Windows, Shift+Option+F on Mac or Ctrl+Shift+I on Linux. Or right-click and choose Format Document. If the file is not recognised as JSON, set the language mode to JSON first.
Are trailing commas allowed in JSON?
No. Standard JSON does not allow a comma after the last item in an object or array. JavaScript and some config formats (JSON5, JSONC) accept them, but JSON.parse and most APIs will reject them.
Can JSON use single quotes?
No. Keys and string values must use double quotes. {'name': 'Asha'} is invalid; {"name": "Asha"} is valid.
Is it safe to paste JSON into an online formatter?
Only if the formatter runs in your browser. API responses and config files often contain tokens, keys and personal data. Our JSON formatter parses everything locally and sends nothing to a server.
How do I minify JSON?
Choose Minify in our JSON formatter to remove all whitespace. On the command line, jq -c . file.json does the same.