JSON Formatter
|
Paste minified or raw JSON and get clean, indented output. The formatter uses your browser's native JSON.parse and JSON.stringify — no server involved, no size limits enforced by the tool.
What the formatter does
It parses your input with JSON.parse and re-serializes it with JSON.stringify(…, null, 2), producing consistently indented output. Nested objects, arrays, and deeply nested structures are all expanded across lines.
If the input cannot be parsed — because of a trailing comma, a single-quoted string, or a missing bracket — the parser error message is shown inline so you can find and fix the problem without guessing.
{"id":1,"user":"alice","active":true,"tags":["dev","admin"]}{
"id": 1,
"user": "alice",
"active": true,
"tags": [
"dev",
"admin"
]
}When you need it
API responses arrive minified. Log files and network inspector outputs paste as single lines. Config files get compressed by build steps. Any of these become unreadable without formatting.
Typical triggers: you copy a response from curl or Postman, paste it into a terminal, and cannot read the structure. Or you receive a payload where a field is missing and need to scan the keys. Or a teammate sends you JSON and you need to understand the shape before writing code against it.
Formatting vs validating
This tool formats valid JSON. It does not repair invalid JSON. Trailing commas (allowed in JavaScript but not JSON), single-quoted strings, and unquoted keys all cause parse errors.
If formatting fails, switch to the JSON Validator to get a clearer error message and line number, then return here once the syntax is fixed.
See also: JSON Validator
JSON syntax rules
JSON is a strict text format defined by ECMA-404 and RFC 8259. A single rule violation causes the entire payload to fail — there is no partial parsing.
Double quotes only — every string value and every object key must use double quotes. Single quotes and backticks are not valid JSON, even though JavaScript accepts them in object literals.
No trailing commas — the last property in an object and the last element in an array must not be followed by a comma. {"a":1,"b":2,} is invalid. {"a":1,"b":2} is valid.
Keys must be quoted strings — object keys cannot be bare identifiers. {name:"Alice"} is a JavaScript object literal syntax, not JSON. {"name":"Alice"} is valid JSON.
No comments — JSON has no comment syntax. // line comments and /* block comments */ both cause parse errors. Strip comments before passing text to a JSON parser.
Balanced braces and brackets — every { must be closed by } and every [ must be closed by ]. Mismatched or unclosed brackets produce "Unexpected end of JSON input" errors.
Common invalid JSON: examples and fixes
These four mistakes account for the large majority of JSON parse errors encountered in practice. Each is shown as an invalid example followed by the corrected version.
{
"name": "alice",
"role": "admin",
}{
"name": "alice",
"role": "admin"
}{'name': 'alice', 'active': true}{"name": "alice", "active": true}{name: "alice", active: true}{"name": "alice", "active": true}{"users": [{"id": 1}, {"id": 2}{"users": [{"id": 1}, {"id": 2}]}Debugging a parse error step by step
When the formatter shows an error instead of formatted output, this workflow finds the problem quickly.
Step 1: read the error message. It includes a character position (e.g., "at position 47"). The parser stopped there — the actual mistake is at or just before that point.
Step 2: check for the most common causes near that position. Is there a trailing comma before a closing } or ]? A single-quoted string? An unquoted key? A stray comment?
Step 3: for large payloads, isolate the region. Paste only the section around the reported position and format that fragment — a smaller input produces a more precise error message.
Step 4: if the error is "Unexpected end of JSON input", the payload is likely truncated. Count { against } and [ against ] — the totals must match. If the JSON came from a log file or a network inspector that wraps long lines, the raw bytes may differ from what is displayed.
JSON value types and precision edge cases
JSON supports six value types: strings, numbers, booleans (true/false), null, objects, and arrays. JSON.parse followed by JSON.stringify preserves all of them exactly — with one important exception: number precision.
JavaScript represents all numbers as 64-bit floats (IEEE 754 double). Integers larger than 2‱53 − 1 (9,007,199,254,740,991) cannot be represented exactly. If an API returns a large integer ID with 16 or more digits, the last digits may change silently after a roundtrip through JSON.parse. The safe workaround is to treat large IDs as strings.
NaN and Infinity are valid JavaScript values but invalid JSON. JSON.stringify converts them to null — so if a value in the formatted output is unexpectedly null, a NaN or Infinity in the original data is a likely cause. undefined values and function-valued properties are silently dropped by JSON.stringify entirely.
{"id": 9007199254740999} → formats as 9007199254741000 after roundtripJSON.stringify({score: NaN}) → {"score":null}JSON.stringify({a:1, b:undefined}) → {"a":1}Frequently Asked Questions
- Why does the formatter reject my JSON?
- The most common reasons: trailing commas after the last property in an object or array, single-quoted strings instead of double-quoted, and unquoted key names. JSON is stricter than JavaScript object syntax. The error message from the parser points to the position where parsing failed.
- Does it modify my data — values, types, key order?
- No. JSON.parse followed by JSON.stringify preserves all values and types. Key order may change in very old environments, but modern V8-based engines preserve insertion order for non-integer keys.
- Is my JSON sent anywhere?
- No. Everything runs in your browser tab using built-in JavaScript functions. Nothing is sent to a server.
- What indentation does it use?
- 2 spaces per level. This matches the most common style in JavaScript codebases and is readable without being too wide.
- My number value changed after formatting — digits at the end are wrong
- JavaScript uses 64-bit floating-point (IEEE 754 double) for all numbers. Integers larger than Number.MAX_SAFE_INTEGER (9,007,199,254,740,991 — about 9 quadrillion) cannot be represented exactly. If the JSON contains a numeric ID with 16 or more digits, the last few digits may change silently during JSON.parse. The solution is to store and transmit large IDs as strings rather than numbers.
- Can I add comments to JSON?
- No. The JSON specification has no comment syntax — // and /* */ both cause parse errors. If you need comments in configuration files, use JSONC (JSON with Comments), which VS Code supports natively for .jsonc files and tsconfig.json. For standard JSON consumed by parsers, strip comments before parsing. The json-strip-comments npm package and many editors can do this automatically.
- What is the difference between JSON and a JavaScript object literal?
- JSON is a text format. A JavaScript object is a runtime value in memory. JSON is stricter: all keys must be double-quoted strings, string values must use double quotes only, functions and undefined cannot be represented, and trailing commas are invalid. JSON.parse converts JSON text into a JavaScript object; JSON.stringify converts a JavaScript object back into JSON text.
- How do I format JSON in the terminal?
- With Python 3 (available on most systems without extra install): python3 -m json.tool file.json, or echo '{"a":1}' | python3 -m json.tool. With jq (install separately, handles large files well): cat file.json | jq . — jq also supports filtering and querying. For a quick one-off check, paste the JSON here and copy the result.
- What is JSONC and can this formatter handle it?
- JSONC is an unofficial extension of JSON that allows // comments and trailing commas. VS Code uses it for settings.json and tsconfig.json. This formatter uses a strict JSON parser and will reject JSONC. To format a JSONC file, strip the comments and trailing commas first (most editors or the json-strip-comments package can do this), then paste the clean JSON here.