What is this calculator for?
You just pasted a 1,400-character API response into your editor and it's one giant line with no whitespace. Or you're debugging an API that returns malformed JSON and the error message is unhelpful. The JSON formatter pretty-prints minified JSON (adding indentation and newlines for readability), validates JSON syntax (identifying exactly where errors are), and minifies pretty-printed JSON when needed for transport efficiency.
JSON (JavaScript Object Notation) is the dominant data interchange format on the modern web. Used by virtually every REST API, configuration file, NoSQL document store, and inter-service communication. JSON syntax: objects (key-value pairs in {}), arrays (in []), strings (double-quoted), numbers, booleans, null. Strict syntax β single quotes don't work; trailing commas are illegal; keys must be strings; comments not allowed.
This formatter accepts JSON input, validates syntax, and outputs formatted or minified versions. Use during API debugging, config file editing, or any time JSON is hard to read in its raw form.
How to use this calculator
Paste your JSON into the input area. The formatter detects whether it's valid JSON and either pretty-prints it (adding indentation and newlines) or shows the syntax error with location.
For minification (removing whitespace for transport): the tool can convert pretty-printed JSON back to compact form. Useful when sending JSON over networks where size matters (API responses, embedded in URLs).
For validation: paste suspicious JSON, the tool reports syntax errors with line and column. Common errors: trailing commas (legal in JavaScript objects but not JSON), single quotes instead of double, unquoted keys, mismatched brackets.
Understanding your results
The formatter outputs either formatted JSON or specific error messages identifying where parsing failed.
JSON syntax essentials. Object: {"key": "value", "key2": 42}. Array: [1, "two", true, null]. Strings: must use double quotes. Numbers: no quotes (123, -45.67, 1.2e3). Booleans: true and false lowercase (Python's True/False capitalization is invalid JSON). Null: null lowercase. Nested: {"user": {"id": 1, "name": "Alice", "tags": ["admin", "owner"]}}.
Common JSON errors. Trailing comma after last item: [1, 2, 3,] β illegal in strict JSON, legal in JavaScript. Single quotes: {'key': 'value'} β illegal. Unquoted keys: {key: "value"} β illegal. Comments: {"x": 1 /* comment */} β illegal. These all work in JavaScript object literals but fail JSON parsing. JSON5 and JSONC are alternative formats that allow these; standard JSON does not.
Pretty-printing indentation. Standard practice: 2-space or 4-space indentation. Default is 2-space in most contexts (Node.js, Python json.dumps default). 4-space is more readable for deeply-nested structures but produces larger files. The choice is aesthetic; consistency within a project matters more than the specific number.
JSON vs alternatives. YAML: more human-readable, allows comments, but indentation-sensitive (whitespace errors common). TOML: configuration-focused, very clean syntax. XML: older, more verbose, still used in legacy systems. JSON's advantages: universal language support (parser in every modern language), simple syntax, compact, well-defined spec (RFC 8259). For data interchange between systems: JSON dominates. For config files: increasingly YAML or TOML. For data within a single system: language-native formats (Python pickle, etc.) sometimes used.
A worked example
Marcus is debugging a webhook integration. The third-party service is supposed to send him JSON but the request fails on his server.
He copies the raw webhook payload from his server logs: {name: "John Doe", email: 'john@example.com', age: 35, items: [1, 2, 3,]}
Pastes into the JSON formatter. Result: Error at line 1, column 2 β Unexpected token 'n' (expected string). The formatter highlights: unquoted key "name." Marcus identifies the first issue.
He fixes manually: {"name": "John Doe", "email": 'john@example.com', age: 35, items: [1, 2, 3,]}. Re-parses. Error: line 1, column 25 β Unexpected token "'" (string must use double quotes). He fixes the email quotes. Re-parses. Error: column 50 β unquoted "age". Fixes. Re-parses. Error at end: trailing comma in array. Fixes. Now parses successfully.
The webhook source is sending JavaScript object literal syntax, not JSON. He contacts the third-party service β they confirm their docs say "JSON" but the actual output is JS-formatted. Fix on their side. In the meantime, Marcus's server-side code is updated to use a lenient parser (jsonc or json5) that accepts the loose format.
Variation: API response that's "valid JSON but ugly." 4-line minified response that's actually a 200-line nested object. Pretty-printed: 200 lines of indented structure that's easy to scan. Marcus can quickly see which fields are present, which are null, which are nested how deeply. The pretty-print transforms the response from "wall of text" to readable structure in 1 click.
Related resources
For testing API endpoints that return JSON, use tools like Postman or curl. For regex pattern testing (often paired with JSON parsing), see Regex Tester. For other developer text tools, the Base64 Tool and URL Encoder. The JSON.org is the official reference for the format; RFC 8259 is the authoritative IETF specification.