How to find JSON errors and format JSON neatly
Checking an API response or editing a config file, you will eventually hit an error like "Unexpected token". A long single-line JSON blob is hard to read, too. Knowing a few JSON rules makes most errors quick to find.
JSON basics
- Objects use
{ }and arrays use[ ]. - Keys must be in double quotes:
"name" - String values use double quotes only. Single quotes are not allowed.
- Valid values are strings, numbers,
true,false,null, objects and arrays. - Comments are not allowed.
The five most common errors
| Error | Wrong | Fixed |
|---|---|---|
| Trailing comma | {"a": 1,} | {"a": 1} |
| Single quotes | {'a': 'x'} | {"a": "x"} |
| Unquoted key | {a: 1} | {"a": 1} |
| Missing comma | {"a": 1 "b": 2} | {"a": 1, "b": 2} |
| Unclosed bracket | {"list": [1, 2} | {"list": [1, 2]} |
JavaScript code allows trailing commas and single quotes, so these errors show up a lot when you paste code into a JSON file.
Finding the error fast
- Paste your JSON into the formatter below.
- If the syntax is wrong, it shows the line, the column and the likely cause.
- Look just before the reported spot first. A missing comma or quote is often one step earlier than where the parser gives up.
- Fix it and format again to get properly indented JSON.
JSON FormatterPretty print, error position, CSV
Open tool
Pretty print or minify
- Format: easy to read and edit, with 2 or 4 space indentation.
- Minify: strips spaces and line breaks for smaller payloads in configs or request bodies.
- Sort keys: alphabetical keys make it easier to compare two JSON files.
- Tree view: handy for finding a value in deeply nested data.
Converting between JSON and CSV
An array of objects can be turned into CSV and opened in Excel or Google Sheets, and CSV can be turned back into a JSON array. Nested arrays or objects end up as text in a single cell.
Safe for sensitive data
JSON often contains API keys or user data. This tool processes everything in your browser, so what you paste is never sent to a server.
Tools in this article
JSON FormatterPretty print, error position, CSV
Open tool