How the JSON Formatter works
The formatter reads your input with a strict JSON parser that follows the JSON standard (RFC 8259). It checks every character as it goes, so the first syntax error is reported with its exact line and column instead of a vague "unexpected token" message.
Once the input is known to be valid, the formatter writes it back out with one value per line and the indentation you chose. It works on the original text of each value rather than converting it to JavaScript numbers and back, so large integers such as database IDs keep all their digits, and strings keep their original escape sequences. Only the whitespace between values changes.
How to use the JSON Formatter
- Paste your JSON into the input box, open a .json file, or select Load example.
- Choose the indentation you want: 2 spaces, 4 spaces or tabs. Tick Sort keys to order object properties alphabetically.
- Select Format JSON, or press Ctrl + Enter (Cmd + Enter on a Mac).
- Copy the formatted result or download it as a .json file. If there is an error, the message shows the line and column and the cursor jumps to it.
Example
This minified input:
{"id":1042,"name":"Wireless Keyboard","tags":["electronics","accessories"],"price":49.99,"inStock":true}
is formatted with 2-space indentation as:
{
"id": 1042,
"name": "Wireless Keyboard",
"tags": [
"electronics",
"accessories"
],
"price": 49.99,
"inStock": true
}
If a comma were missing after 1042, the tool would report
Invalid JSON at line 1, column 11: Expected ',' or '}' after property value but found '"'.
Common use cases
- Reading a minified API response copied from browser developer tools or a log file.
- Tidying configuration files such as appsettings.json, package.json or tsconfig.json before committing them.
- Producing consistently indented JSON so code reviews show real changes instead of whitespace noise.
- Finding the exact position of a syntax error, such as a missing comma, in a large payload.
- Sorting keys so two JSON documents can be compared side by side more easily.
Common errors and how to fix them
- The error says: Expected ',' or '}' after property value
- A value is not followed by a comma or a closing brace. The usual cause is a missing comma between two properties, or a stray double quote that ended a string early. The cursor jumps to the reported column, so check the characters immediately before it.
- The error mentions comments, single quotes or trailing commas
- The input is relaxed or JavaScript-style JSON rather than standard JSON, and this formatter is strict on purpose. Run it through the JSON Beautifier first, which repairs comments, single quotes and trailing commas, then format the repaired output here.
- Unterminated string: a line break is not allowed inside a string
- A string was opened but a real newline appeared before its closing quote. Replace the line break with the escape sequence \n, or look for a missing closing double quote earlier on the same line.
- The output looks identical to the input
- The JSON was already indented exactly the way you asked for. Change the indentation setting, or tick Sort keys, to confirm the tool ran.
Frequently asked questions
Does the JSON formatter change my data?
No. It only changes whitespace between tokens. Strings, numbers and key order are kept exactly as written, unless you choose Sort keys, which reorders object properties alphabetically without changing their values.
Why are large numbers kept exactly?
Many online formatters convert JSON to JavaScript numbers, which silently rounds values larger than 9,007,199,254,740,991. This formatter re-prints number literals as they appear in your input, so long IDs keep every digit.
What happens if my JSON is invalid?
Formatting stops and an error message shows the line, column and the reason, for example an unexpected character or a missing comma. The cursor is moved to the error in the input box so you can fix it.
Can I format JSON that contains comments or trailing commas?
Standard JSON does not allow comments, single quotes or trailing commas, so the formatter reports them as errors. Use the JSON Beautifier, which is designed to repair that kind of relaxed JSON.
Is there a size limit?
Formatting runs in your browser, so the practical limit depends on your device. Files of several megabytes format in well under a second on a typical computer. The tool accepts input up to 20 MB.
Is my JSON uploaded to your server?
No. The formatting is done by JavaScript in your browser, and the JSON you paste or open is not sent to our server.