JSON Formatter
What is JSON Formatter?
The JSON Formatter makes compact or messy JSON readable by adding indentation, line breaks, and visible structure. JSON is used in API responses, configuration files, logs, feature flags, test data, and no-code integrations, where a missing comma, wrong quote, or unexpected nested value can immediately cause parsing errors. This tool helps inspect objects, arrays, keys, values, and likely error locations quickly, and it can also compact JSON again when a smaller payload is needed. Formatting does not change the meaning of the data and does not automatically validate a business schema. For production APIs, field types, required properties, null handling, and version contracts still need separate checks.
How to Use
How to use
- Paste or enter JSON data in the left input box
- Select indent size (2 spaces, 4 spaces, or Tab)
- Click Format to beautify or Minify to remove whitespace
- Results appear automatically on the right with syntax highlighting
- Click Copy or Download to save the result
JSON Validation Notes
- Formatting proves the text is valid JSON, but it does not prove the data matches your business schema.
- When errors appear, check the reported line and column for single quotes, trailing commas, comments, or unescaped control characters.
Use Cases
Technical Principle
JSON (JavaScript Object Notation) is defined by RFC 8259 / ECMA-404. The grammar is a strict subset of JavaScript object literals: strings must be wrapped in double quotes, keys must be quoted, trailing commas are illegal, and comments are forbidden. A formatter parses the document with `JSON.parse()` into the host language object graph, then re-serializes via `JSON.stringify(value, replacer, indent)` where indent is a number (1-10 spaces) or a string (`'\t'`). Parsing is O(n) and is generally faster than the stringify phase because output building allocates new strings. Number handling follows IEEE 754 double precision: integers larger than `Number.MAX_SAFE_INTEGER` (2^53 - 1 = 9007199254740991) lose precision, so `9007199254740993` round-trips to `9007199254740992`. Decimal repeats such as `0.1 + 0.2` resolve to `0.30000000000000004` after parse. Unicode strings allow `\uXXXX` escapes including surrogate pairs (`\uD83D\uDE00` → 😀); the parser rejects lone unpaired surrogates. Whitespace is significant only inside strings - any combination of space, tab, LF, CR between tokens parses identically. Common non-standard relaxations are JSON5 (comments, trailing commas, unquoted keys) and JSONC (VS Code config). Standard JSON does not allow them and `JSON.parse` throws `SyntaxError` on encounter. Streaming alternatives such as NDJSON (one object per line) and JSON Lines avoid loading entire documents into memory. For deeply nested input, the V8 stack limit (~10,000 frames) caps recursion-based parsers; production parsers use iterative state machines to lift the ceiling.
- RFC 8259 / ECMA-404 grammar - six value types (object, array, string, number, true/false, null); strings double-quoted; keys must be quoted; no trailing commas; no comments.
- `JSON.parse(text)` runs in O(n) and throws `SyntaxError` with character offset on invalid input; `JSON.stringify(value, replacer, indent)` produces formatted output with 2-10 space or `'\t'` indentation.
- IEEE 754 number precision: `Number.MAX_SAFE_INTEGER = 2^53 - 1`; integers beyond this round to the nearest representable double, so chat IDs and Twitter Snowflake IDs must be transported as strings.
- Unicode `\uXXXX` escapes support full BMP; non-BMP characters require surrogate pair encoding `\uD83D\uDE00`; the parser rejects lone unpaired surrogates per RFC 8259 §8.2.
- Common parse failures: single-quoted strings (`'foo'`), trailing comma after the last array/object item, unescaped control characters inside strings, unescaped backslash, missing closing `}`/`]`, BOM (`\uFEFF`) at start.
- Circular references throw `TypeError: cyclic object value` in `JSON.stringify`; use a `replacer` callback with a WeakSet to break cycles, or libraries like `flatted` / `json-stringify-safe`.
- Non-standard variants: JSON5 (`.json5`, allows comments and trailing commas), JSONC (VS Code config), NDJSON / JSON Lines (one object per line, streaming-friendly) - all rejected by strict `JSON.parse`.
Examples
Object Example
Input:
{
"name": "ToolAct",
"type": "web tool",
"active": true
}
Output: pretty-printed with 2-space indent and stable key orderArray Example
Input: [1,2,3,"a","b","c"]
Output: formatted with 2-space indent; numbers stay numeric, strings keep quotesNested Structure
Input:
{"user":{"name":"Alex","skills":["JavaScript","Python"]}}
Output:
{
"user": {
"name": "Alex",
"skills": [
"JavaScript",
"Python"
]
}
}
Note: nested objects and arrays are indented recursively; choose the indent width in the toolbarFAQ
What does the formatter do?
Reformats JSON: pretty-print with chosen indent (2 or 4 spaces), or minify to a single line. Validates as it parses, so syntax errors are reported with line and column.
Why is my JSON rejected as invalid?
Common causes: trailing commas (legal in JS, illegal in JSON), single-quoted strings (must be double), unquoted keys, comments (// or /* */), or missing brackets. The page reports the parse failure location. JSON5 and JSONC (JSON with comments) are supersets of JSON - use a different parser for those.
Will it preserve key order?
JSON spec says key order is not significant but most parsers preserve it on round-trip. This tool keeps insertion order, which is usually what you want for readable diffs.
Can it handle very large JSON files?
Modern browsers handle 10-50 MB JSON files but may slow the editor. For multi-hundred-MB files, use a streaming parser (jq command-line, ndjson tools); browser parsers load the whole tree into memory.
Is my JSON uploaded?
No. Parsing and formatting run in your browser via JSON.parse and JSON.stringify. Pasted JSON is not transmitted.
Why are big numbers losing precision?
JavaScript JSON.parse uses Number, which is IEEE 754 double precision. Integers above 2^53 lose precision (e.g. 9007199254740993 silently rounds). For BigInt or string-preserving parsing, use a custom parser or pre-mark big numbers as strings in the producer.
What about JSONC (JSON with comments)?
Strict JSON forbids comments. Some IDEs (VS Code config files) use JSONC, which adds // and /* */ comments. The formatter typically supports a 'JSONC' mode that preserves comments; in strict mode comments are a syntax error.