JSON Formatter & Validator
Paste in JSON to pretty-print, minify, or validate it β with exact line and column numbers when something's broken.
Output will appear hereβ¦
How to use it
- Paste or type your JSON into the box above β a full document, or just an object or array fragment.
- Pick an indent size if you're formatting (2 spaces is the most common convention; tabs work too).
- Click Format / Beautify to pretty-print it, or Minify to strip it down to a single compact line.
- If the JSON is invalid, an error box shows the line, column, and the surrounding text so you can find the problem fast.
- Click Copy to grab the result β a "Copied!" confirmation flashes so you know it worked.
What's actually happening
This tool leans entirely on the browser's built-in JSON.parse() and JSON.stringify() β the same parser your browser's JavaScript engine uses everywhere else, so what validates here will validate in your code too. Formatting calls JSON.stringify(data, null, indent), where the third argument controls the indentation. Minifying calls the same function with no indent argument, which collapses all whitespace between tokens.
Validation is really just "does JSON.parse() throw?" When it does, the thrown SyntaxError includes a character offset into the string. This tool walks the input up to that offset counting newlines, converts it into a 1-based line and column number, and slices out the surrounding text so you're not stuck guessing which of your 400 lines has the problem.
Worked example
Here's a real case: a config file with a trailing comma, a common copy-paste mistake when adding a new field.
{
"env": "production",
"retries": 3,
"timeoutMs": 5000,
}
Unexpected token '}'
at line 5, column 1
"timeoutMs": 5000,
^
Removing the comma after 5000 and clicking Format produces:
{
"env": "production",
"retries": 3,
"timeoutMs": 5000
}
Reference: valid vs. invalid JSON
| Pattern | Valid JSON? | Why |
|---|---|---|
{"a": 1,} | β No | Trailing comma not allowed |
{'a': 1} | β No | Keys and strings must use double quotes |
{a: 1} | β No | Keys must be quoted strings |
// comment | β No | JSON has no comment syntax |
{"a": undefined} | β No | undefined isn't a JSON value β use null |
{"a": NaN} | β No | JSON numbers can't be NaN or Infinity |
{"a": null} | β Yes | null is a valid JSON value |
[1, 2, 3] | β Yes | A top-level array is valid JSON |
Frequently asked questions
Why does my JSON say "Unexpected token" when it looks fine to me?
The most common causes are a trailing comma after the last item in an object or array, single quotes instead of double quotes around strings and keys, or an unquoted key. JSON is stricter than JavaScript object literals β no trailing commas, no comments, no single-quoted strings.
Can I format JSON that contains comments?
No. Standard JSON has no comment syntax, so a formatter that accepts comments isn't parsing real JSON β it's parsing a superset like JSON5 or JSONC. This tool validates strict JSON, matching what JSON.parse() and virtually every API and config loader expects.
What does "minify" actually do to my JSON?
It removes all insignificant whitespace β indentation and line breaks used for human readability β without changing the data. The parsed structure is identical; only the serialized text gets shorter, which matters for payload size over the wire.
Does this tool support very large JSON files?
It runs entirely in your browser using the built-in JSON parser, so it handles several megabytes without issue on most machines. Extremely large files (tens of MB) may feel sluggish because the whole string is held in memory and re-rendered, not because of a hard size limit.
Is my JSON data sent anywhere when I use this tool?
No. Parsing and formatting happen with JavaScript running locally in your browser tab. Nothing you paste is transmitted to a server, logged, or stored β closing the tab clears it completely.
Why does the formatter show a line and column number for errors?
JavaScript's native JSON.parse() throws a SyntaxError with a character position in its message. This tool converts that position into a line and column number and shows the surrounding text so you can jump straight to the problem.
About this tool
JSON.parse()/JSON.stringify() β there's no custom parser here to disagree with your runtime. One limitation: this tool does not preserve key order guarantees beyond what JavaScript objects already provide (insertion order for string keys, which is what modern engines use), and very deeply nested structures may hit the browser's own recursion limits before this tool's.