LIVE
0 words
0 chars
0 lines
en-US lang

JSON Formatter

Format, validate and minify JSON data with syntax highlighting.

local-only instant no upload
— Text Tools Online
✎ NOTES ON THIS TOOL

You Have Pasted a Wall of JSON and Have No Idea Where the Error Is

It has happened to every developer. You call an API, log the raw response, paste it into your code — and something breaks. Or you open a configuration file that was hand-edited by a colleague and it fails to parse. The JSON is a single unbroken line, 4,000 characters wide, and the parser error just says "unexpected token at position 1,847."

A JSON formatter solves this in one paste: it adds proper indentation so the structure becomes visible, and it pinpoints exactly where the syntax error is rather than leaving you to count characters manually.

The Most Common JSON Errors and Why They Happen

JSON has strict syntax rules that trip up even experienced developers, especially when JSON is written by hand or generated by tools that do not enforce the spec:

  • Trailing commas: {"a": 1, "b": 2,} — JavaScript allows trailing commas in objects and arrays; JSON does not. This is probably the most frequent error in hand-written JSON.
  • Single quotes instead of double quotes: JSON requires double quotes for all strings. {'key': 'value'} is valid JavaScript but invalid JSON.
  • Unquoted keys: {key: "value"} is valid in JavaScript object literals but not in JSON. All keys must be quoted strings.
  • Unescaped special characters in strings: Backslashes, double quotes, and control characters inside string values must be escaped. A Windows file path like "C:\Users\name" must be written as "C:\Users\name".
  • Comments: JSON does not support comments. // this is a comment or /* block comment */ will cause a parse failure. If you need comments in a config file, consider JSONC or YAML instead.
  • Numbers written as strings without quotes, or vice versa: {"port": "8080"} and {"port": 8080} are both valid JSON but have different types — many APIs are strict about this distinction.

Format vs Minify: When to Use Each

Formatting adds indentation (typically 2 or 4 spaces per level) and line breaks, making the structure human-readable. Use it whenever you are reading or debugging JSON.

Minifying strips all whitespace that is not inside string values, producing the most compact representation. Use minified JSON in production API responses and configuration files where every byte matters — a formatted JSON file can be 30–50% larger than its minified equivalent purely due to whitespace.

Crucially, formatted and minified JSON are semantically identical. The data they represent is exactly the same; only the presentation differs. Any JSON parser will produce the same in-memory structure from both forms.

Reading Deeply Nested JSON

Complex API responses often nest objects several levels deep — a user object containing an address object containing a coordinates object. After formatting, use the tree view or collapsible sections (if your formatter supports them) to collapse subtrees you do not need to inspect. This lets you focus on the part of the structure that is relevant to your debugging task without losing the overall context.

Questions

01 Does minified JSON behave differently from formatted JSON at runtime? +

No. Formatted and minified JSON are semantically identical — every JSON parser produces the same data structure from both. The only practical difference is file size and human readability. Minified JSON saves bandwidth and storage; formatted JSON is easier to inspect and debug.

02 Why does JSON not allow trailing commas, even though JavaScript does? +

JSON was designed as a strict, language-agnostic data format — not as JavaScript syntax. Douglas Crockford, who formalised the JSON spec, deliberately excluded trailing commas to ensure unambiguous parsing across all languages and platforms. JavaScript later relaxed this rule for its own object literals, but JSON itself has never changed.

03 My JSON has comments and the formatter rejects it — is there a fix? +

JSON does not support comments per the spec. If your file uses comments, it is likely JSONC (JSON with Comments), which is used by VS Code configuration files and TypeScript config. You can strip comments manually or use a JSONC-aware parser. This formatter validates against the standard JSON spec, so commented JSON will show as invalid.

04 How do I handle JSON with special characters like newlines inside string values? +

Literal newlines cannot appear inside JSON string values — they must be represented as the escape sequence \n. Similarly, tabs must be \t, carriage returns must be \r, and double quotes must be \". If you see an "unterminated string" error, check whether your string values contain unescaped control characters.