ToolActToolAct

JSON Formatter

JSON Input
Formatted Output
Lines: 1Characters: 0Bytes: 0
Lines: 1Characters: 0

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

  1. Paste or enter JSON data in the left input box
  2. Select indent size (2 spaces, 4 spaces, or Tab)
  3. Click Format to beautify or Minify to remove whitespace
  4. Results appear automatically on the right with syntax highlighting
  5. 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

Inspecting API responses without leaving the browserPaste a compact response body to expand nested objects and arrays with two spaces, four spaces, or tabs. Parse errors include a calculated line and column when possible, so a malformed response can be fixed without hunting through the whole document by eye.
Preparing JSON for commits and reviewsWhen configuration, sample fixtures, or translation data needs a stable layout, the formatter produces deterministic output with the selected indentation. Minify mode is available for the opposite direction when the same data must be copied into an environment variable or request field.
Cleaning sensitive data locallyThe parser, formatter, minifier, copy, and download steps all run in the browser, keeping tokens, customer fields, internal feature flags, and unreleased API shapes away from third-party beautifiers. Validate the output against the OpenAPI or JSON Schema spec separately, since formatting proves the document parses but does not prove the data matches the contract your consumers expect, and watch for silent type coercion on large numeric fields.
Diff two JSON payloads field by fieldFormat both an old and a new response with matching indentation, then align them side by side in a diff viewer to spot renamed keys, type changes, and null vs. missing field differences. This is faster than scanning raw minified JSON, especially for webhook payloads where a single swapped field breaks consumers.
Compact for environment variables or curl payloadsSwitch to minify mode to fit a large configuration blob into a single-line environment variable, .env file, or curl --data argument. Confirm with the target parser afterward, since some HTTP clients still struggle with very long single-line bodies over a few hundred kilobytes. Strict JSON (RFC 8259) forbids trailing commas and comments, so when the input is JSON5 or HJSON, the strict parser will reject lines that begin with `//` or end with `,]`; in that case, enable a tolerant mode or strip the comments before formatting. Large integer values above 2^53 lose precision because JavaScript represents them as IEEE-754 doubles.

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 order

Array Example

Input:  [1,2,3,"a","b","c"]
Output: formatted with 2-space indent; numbers stay numeric, strings keep quotes

Nested 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 toolbar

FAQ

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.