How to use the JSON Formatter
- Paste your JSON into the input box above. It can be anything: an API response, a config file, a log entry and so on.
- Pick an indentation style (2 spaces, 4 spaces or tab) and click Beautify to get cleanly formatted output.
- If there is a syntax error, a red message shows the line and column of the error, and the cursor jumps to that spot in the input box.
- To make the payload smaller, click Minify to strip out all spaces and line breaks. You can copy the result or save it as a .json file.
Common JSON syntax errors
JSON looks a lot like JavaScript object notation, but its rules are stricter. If validation fails, check these common mistakes first.
| Invalid | Valid | Why |
|---|---|---|
{'name': 'smith'} | {"name": "smith"} | Strings and keys must use double quotes |
{name: "smith"} | {"name": "smith"} | Keys need quotes too |
[1, 2, 3,] | [1, 2, 3] | Trailing commas aren't allowed |
{"a": undefined} | {"a": null} | undefined, NaN and Infinity aren't valid values |
// comment | (remove it) | JSON doesn't support comments |
{"n": 012} | {"n": 12} | Numbers can't have leading zeros |
The reported position is the first place where a rule breaks. The real mistake may be earlier, such as a missing closing bracket, so check the line just above the one shown as well.
When should you beautify or minify JSON?
Beautify (also called pretty printing) is for people. Use it to inspect API responses, edit config files or explain a data structure in a code review. Match your team's style for indentation: JavaScript projects usually use 2 spaces, and Python projects often use 4.
Minify is for machines. It removes every space and line break to make the data smaller, which helps when you send it over a network, write it to a log as a single line or store JSON in an environment variable. The data means exactly the same thing as the beautified version.
Sort keys alphabetically reorders the keys in every object. This keeps diffs clean when you compare two JSON files, because differences in key order no longer show up as changes. Array items stay in their original order, since order in an array is meaningful.
JSON data types at a glance
- Object
{ }: a collection of "key": value pairs. Keys must be strings. - Array
[ ]: an ordered list of values. You can mix different types. - String: wrapped in double quotes. Write a line break as
\nand a double quote as\". Accented letters, other non-English text and emoji can be used as is. - Number: integers, decimals and exponent notation (1e3) are allowed. If you add quotes, the value becomes a string.
- true / false / null: always lowercase.
To turn spreadsheet data from Excel or Google Sheets into JSON, try the CSV to JSON converter. To pull JSON out of an encoded token, use the Base64 decoder.