๐งฉ JSON Formatter: Format, Validate and Minify JSON Online
By Shihab Mia ยท Updated 2026-08-03
Paste JSON above, then choose Format, Minify, or Validate.
This JSON formatter cleans up messy JSON in one click. Paste your data and choose Format to pretty print it with neat indentation, Minify to strip every space and newline into a single compact line, or Validate to confirm it parses and see the exact error if it does not. Everything runs in your browser using the JavaScript engine's own JSON.parse, so your data never leaves the page, which matters when you are pasting API responses, tokens, or config that might be sensitive.
What is the JSON Formatter?
JSON (JavaScript Object Notation) is the most common format for sending structured data between programs: API responses, config files, log records, and database documents are usually JSON. It is built from a few simple pieces, objects in curly braces holding "key": value pairs, arrays in square brackets, strings in double quotes, numbers, and the literals true, false and null, all nested as deeply as needed. Despite the name, JSON is not tied to JavaScript, it is a language-independent text format defined by the standard RFC 8259, and every major language, Python, Java, PHP, Go, Ruby, C#, has a built-in or standard-library way to read and write it. A formatter does not change what the data means, it only changes the whitespace so a human can read it.
Formatting (also called beautifying or pretty printing) adds line breaks and indentation so the nesting is visible at a glance. Minifying does the opposite, it removes all the optional whitespace to make the payload as small as possible, which is what you want when sending JSON over a network or storing it in a database column. Because whitespace outside of strings is not significant in JSON, the two forms are exactly equivalent to a parser, the same object can round-trip from pretty to minified and back without losing anything. Shaving whitespace from a large payload is not just cosmetic either, on a response with thousands of fields it can meaningfully cut transfer size before gzip even runs.
Validating is the step people skip and then regret. A single trailing comma, a missing quote, or a stray curly brace makes the whole document unparseable, and the error a server returns is often vague, something like "Unexpected end of JSON input" with no line number. This tool uses the browser's own JSON.parse, the same strict parser your JavaScript code uses at runtime, so if it accepts your text then any standards-compliant parser, in any language, will too. When parsing fails it shows you the engine's own message, which usually names the position or token that broke, so you can jump straight to the problem instead of scanning the whole document by eye.
JSON deliberately leaves some things out that other formats support. There is no date type (dates are usually sent as ISO 8601 strings), no comments, no trailing commas, and no way to write NaN or Infinity as a number. Object keys must always be strings in double quotes, never single quotes and never left bare. Numbers cannot have a leading zero (007 is invalid, 7 is not) and very large integers can silently lose precision once they exceed about 2^53, because JSON numbers are typically parsed into a JavaScript double. Knowing these limits explains most of the "why is my JSON invalid" surprises people run into when converting from a more permissive format like JavaScript object literals or Python dictionaries.
JSON versus its closest rivals: compared to XML, JSON has no closing tags and no attributes, which makes it noticeably shorter and quicker to parse, at the cost of having no native comments or schema built into the syntax itself (JSON Schema exists but is a separate, optional standard). Compared to YAML, JSON is stricter and less forgiving of formatting, but that strictness is exactly why it is faster to parse and less prone to whitespace-related bugs, which is why nearly every public web API returns JSON rather than YAML. This formatter targets that strict, standard JSON, not JSON5, JSONC, or YAML, so it will correctly reject inputs that a more relaxed parser might accept.
When to use it
- Reading a minified API response by expanding it into readable, indented JSON.
- Shrinking a formatted config or payload to one line before sending it over the network or pasting into a single-line field or environment variable.
- Checking whether a hand-edited config file, such as package.json or tsconfig.json, is valid JSON before deploying it.
- Pinpointing a syntax error, a stray comma or missing quote, from the exact parser message instead of hunting through the document by eye.
- Tidying JSON copied from logs, a database column, or a chat message so it is easy to scan during debugging.
- Comparing a request payload against API documentation by formatting both into the same readable shape.
How to use the JSON Formatter
- Paste or type your JSON into the input box.
- Pick an indent size (2 spaces, 4 spaces, or a tab) if you plan to format.
- Click Format to pretty print, Minify to compress to one line, or Validate to just check it.
- Read the status line: it confirms valid JSON, shows the top-level type, or shows the exact parse error.
- Click Copy to put the result on your clipboard.
Formula & method
Worked examples
You paste the minified object {"name":"Ada","tags":["math","code"]} and click Format with a 2-space indent.
- The tool runs JSON.parse on the text, which succeeds, giving an object with two keys.
- It then runs JSON.stringify(value, null, 2) to add line breaks and indentation.
- Each key sits on its own line, and the array items are indented one level deeper.
Result: { "name": "Ada", "tags": [ "math", "code" ] }
You paste {"a": 1, "b": 2,} (note the trailing comma) and click Validate.
- JSON.parse rejects the trailing comma, because JSON does not allow one after the last item.
- The parser throws a SyntaxError naming the position of the bad token.
- The tool shows the message instead of any output, so you know exactly what to fix.
Result: Invalid JSON: a message like "Unexpected token } in JSON at position 16". Remove the comma after 2.
You paste a nested object {"user":{"id":7,"active":true,"roles":["admin","editor"]}} and click Minify.
- The tool parses the text successfully into an object with a nested "user" object.
- It runs JSON.stringify(value) with no indent argument, which drops every space and line break.
- The result is the same data as a single unbroken line, byte for byte equivalent to the input for any JSON parser.
Result: {"user":{"id":7,"active":true,"roles":["admin","editor"]}}
JSON value types and how they are written
| Type | Example | Notes |
|---|---|---|
| Object | { "key": "value" } | Keys must be double-quoted strings, order is preserved on output. |
| Array | [ 1, 2, 3 ] | Ordered list, any value types, no trailing comma. |
| String | "hello" | Double quotes only, never single quotes, backslash escapes special characters. |
| Number | 42, -3.14, 1e6 | No leading zeros, no NaN or Infinity, decimal point needs a leading digit. |
| Boolean | true, false | Lowercase only, never quoted. |
| Null | null | Lowercase, represents an empty or missing value. |
Common JSON mistakes the validator will reject
| Mistake | Wrong | Correct |
|---|---|---|
| Trailing comma | [1, 2, 3,] | [1, 2, 3] |
| Single quotes | {'a': 1} | {"a": 1} |
| Unquoted key | {a: 1} | {"a": 1} |
| Comment | {"a": 1} // note | {"a": 1} |
| Leading zero | {"n": 007} | {"n": 7} |
| Undefined or NaN | {"n": undefined} | {"n": null} |
JSON escape sequences inside strings
| Escape | Meaning |
|---|---|
| \" | Double quote |
| \\ | Backslash |
| \n | Newline |
| \t | Tab |
| \r | Carriage return |
| \uXXXX | Any Unicode character by its 4-digit hex code point |
Common mistakes to avoid
- Leaving a trailing comma. JSON forbids a comma after the last item in an object or array, even though JavaScript object literals allow it. Remove the final comma before the closing bracket or brace.
- Using single quotes. JSON strings and keys must use double quotes. Single quotes are valid in JavaScript but not in JSON, so {'a': 1} fails while {"a": 1} works.
- Forgetting to quote object keys. Every key in a JSON object is a string and must be wrapped in double quotes. {name: "Ada"} is invalid, {"name": "Ada"} is correct.
- Adding comments. Standard JSON has no comment syntax. Lines starting with // or wrapped in /* */ will cause a parse error. Strip comments, or use a superset format like JSON5 or JSONC that is not interchangeable with strict JSON.
- Pasting a JavaScript object instead of JSON. Code with unquoted keys, single quotes, or trailing commas is a JavaScript object literal, not JSON. Convert it to strict JSON, quoted keys, double quotes, no trailing commas, before formatting.
- Expecting large integers to survive round-trip exactly. JSON numbers are commonly parsed into a 64-bit floating point value, which loses precision above about 2^53 (roughly 9 quadrillion). IDs or timestamps that large should be sent as strings, not bare numbers, if exactness matters.
Glossary
- JSON
- JavaScript Object Notation, a text format for representing structured data as objects, arrays, and primitive values, standardized as RFC 8259.
- Beautify / pretty-print
- Adding line breaks and indentation so nested JSON is easy for a human to read.
- Minify
- Removing all optional whitespace so the JSON is as small as possible for storage or transfer.
- Validate
- Checking that text is well-formed JSON that a parser will accept, and reporting any syntax error.
- Parse
- Reading JSON text and turning it into an in-memory value such as an object or array.
- Indent
- The number of spaces (or a tab) used at each nesting level when pretty printing.
- Serialize
- The reverse of parsing, turning an in-memory value back into JSON text, done by JSON.stringify in JavaScript.
- JSON Schema
- A separate, optional specification for describing the shape and constraints a JSON document must follow, not required to write or read plain JSON.
Frequently asked questions
How do I format JSON online?
Paste your JSON into the input box and click Format. The tool parses it and re-prints it with line breaks and your chosen indentation, 2 spaces, 4 spaces, or a tab. It runs entirely in your browser, so nothing is uploaded.
What is the difference between formatting and minifying JSON?
Formatting, also called beautifying, adds whitespace and indentation to make JSON readable. Minifying removes all optional whitespace to make it as small as possible. Both produce identical data to a parser, since whitespace outside of strings is not significant in JSON.
How do I know if my JSON is valid?
Click Validate. The tool runs the browser's strict JSON.parse on your text. If it parses, you see a confirmation and the top-level type, object, array, string, number, boolean, or null. If not, you see the exact parser error message, which usually names the position or token that broke.
Why does my JSON say it is invalid?
The most common causes are a trailing comma, single quotes instead of double quotes, unquoted object keys, comments, or a missing bracket or brace. The error message points to the offending position so you can fix it quickly.
Is my data sent to a server?
No. All parsing, formatting, and minifying happen in your browser with JavaScript. Your JSON never leaves the page, which makes the tool safe for sensitive API responses, tokens, or config.
Can JSON have comments?
No. Standard JSON has no comment syntax, so // or /* */ will cause a parse error. If you need comments, use a superset like JSON5 or JSONC, but remove them before using strict JSON parsers or APIs.
Can JSON have trailing commas?
No. Unlike JavaScript object and array literals, standard JSON does not allow a comma after the last item. A trailing comma is one of the most common reasons validation fails.
What is the difference between JSON and a JavaScript object?
A JavaScript object literal is code, it can have unquoted keys, single quotes, trailing commas, comments, and even functions. JSON is a strict text format, a subset of that syntax, with double-quoted keys and strings, no comments, and no trailing commas. Every valid JSON document is valid JavaScript, but not every JavaScript object literal is valid JSON.
Why do large numbers in my JSON change after formatting?
JSON numbers are typically parsed as 64-bit floating point values, which can only represent integers exactly up to about 2^53. IDs, snowflake identifiers, or timestamps larger than that can lose precision during parsing. Send them as quoted strings instead of bare numbers if you need exact round-tripping.
What file extension and content type does JSON use?
JSON files typically use the .json extension, and JSON sent over HTTP uses the Content-Type header application/json. Browsers and servers use that header to decide how to parse the body.
Does JSON support dates?
No, JSON has no native date or time type. Dates are almost always sent as strings in ISO 8601 format, for example "2026-08-03T14:30:00Z", and the receiving program is responsible for parsing that string into a real date object.