How to use the JSON formatter
- Paste your JSON into the input box. It can be a single object, an array, or any valid JSON value.
- Press Format to pretty-print it with 2 spaces, 4 spaces or tabs, or Minify to strip all whitespace.
- Press Validate if you only want to know whether the JSON is valid and what its top-level type is.
- Use Copy result to put the output on your clipboard.
Parsing uses your browser's built-in JSON.parse, which follows the JSON standard (RFC 8259) strictly. That means the result here matches what a real API client or fetch().json() call will accept.
Worked example
This minified response from an API is hard to read:
{"id":42,"tags":["a","b"],"owner":{"name":"Sam","active":true}}
After pressing Format with 2-space indentation you get:
{
"id": 42,
"tags": [
"a",
"b"
],
"owner": {
"name": "Sam",
"active": true
}
}
Minify does the reverse, which is useful before pasting JSON into an environment variable, a config field or a URL parameter where whitespace is wasted space.
Common JSON errors and how to fix them
When validation fails, the tool shows the line and column of the first problem, marks it with a caret and selects the character in the input box. The most frequent causes are:
- Trailing comma –
{"a": 1,}or[1, 2,]. JavaScript allows this, JSON does not. Delete the last comma. - Single quotes –
{'a': 'b'}. JSON strings and keys must use double quotes. - Unquoted keys –
{a: 1}is a JavaScript object literal, not JSON. Write{"a": 1}. - Comments –
//and/* */are not part of JSON. Files such astsconfig.jsonuse a relaxed variant (JSONC); remove the comments before validating here. - Unescaped characters in strings – a raw line break or tab inside a string, or a backslash in a Windows path like
"C:\new". Escape them as\n,\tand\\. - Special values –
NaN,Infinityandundefinedare not valid JSON. Usenullor a string. - Unexpected end of input – a missing closing
}or], often because the text was cut off when copying from a log.
Note that the error position points to where the parser gave up, which is sometimes one token after the real mistake. If the reported column looks fine, check the character just before it.
Is my data safe?
Yes. The page has no server-side component for the tool: formatting and validation happen in JavaScript on your device. You can disconnect from the internet after the page has loaded and it keeps working. That makes it suitable for API responses that contain tokens, customer records or other data you should not paste into random websites.
Frequently asked questions
Does this JSON formatter send my data to a server?
No. The JSON is parsed and formatted by JavaScript running in your browser. Nothing you paste is uploaded, logged or stored.
Why does the validator say my JSON is invalid when it works in JavaScript?
JavaScript object literals allow single quotes, unquoted keys, trailing commas and comments. Strict JSON allows none of these, so code that runs in JavaScript can still be invalid JSON.
What does the line and column in the error mean?
They show where the parser stopped. Lines start at 1 at the top of the input and columns count characters from the start of that line. The real mistake is usually at that position or just before it.
Can it format very large JSON files?
It can handle files of several megabytes, limited only by your device's memory. Very large inputs may take a moment, because the whole document is parsed before it is shown.
Does formatting change my data?
Formatting only changes whitespace. One exception applies to all standard JSON parsers: if an object contains the same key twice, only the last value is kept, and very large integers beyond 2^53 lose precision.