toolgarden.xyz
中文

JSON Formatter

Free online JSON / JSONC / JSON5 formatter to format, minify, and validate data with comments, trailing commas, tree view, and node operations

Input JSON

Output

Formatted result will appear here

About this tool

JSON says nothing about indentation or line breaks, which is why API responses usually arrive minified onto a single line. Formatting re-lays that text out as an indented hierarchy so the nesting becomes readable; minifying does the reverse and strips every unnecessary whitespace character to cut transfer size. Both operations touch whitespace only; never the data.

Strict JSON (RFC 8259) forbids comments, trailing commas, single-quoted strings and unquoted keys, yet config files use all of them: tsconfig.json and VS Code settings.json are JSONC, and some toolchains use JSON5. The parser here accepts all three and re-emits strict JSON, so you can paste a commented config file directly instead of stripping comments by hand first.

When parsing fails the error points at the offending position. The three usual causes are an unescaped double quote inside a string, a trailing comma after the last member of an object, and escape backslashes picked up when copying out of a log line. The last two are what JSON Repair is for.

How to use it

  1. Paste or type your JSON

    The input accepts pasted and typed text. Roughly 300 ms after you stop typing it formats once automatically, so normal use needs no button press.

  2. Pick an output shape

    Format emits multi-line JSON with two-space indentation; Minify emits a single line with all whitespace removed. URL and Uni codecs recursively transform string values only, preserving keys, arrays, and object structure.

  3. Locate fields in the tree view

    Formatted output renders as a collapsible tree. For deeply nested documents, collapse everything first and expand down to the path you care about; faster than counting brackets in plain text.

  4. Copy or download the result

    Copy writes the current output to the clipboard. Download saves the complete formatted, minified, or value-transformed JSON as formatted.json.

Input and output example

The same document in both shapes. The minified form fits in an environment variable or request body; the formatted form is what you want in review.

Minified, single line
{"name":"ToolGarden","tags":["json","pdf"],"limits":{"maxDepth":64,"strict":false}}
Formatted, two-space indent
{
  "name": "ToolGarden",
  "tags": [
    "json",
    "pdf"
  ],
  "limits": {
    "maxDepth": 64,
    "strict": false
  }
}

Supported range and limits

Accepted input
Strict JSON (RFC 8259), JSONC (comments and trailing commas), JSON5 (single quotes, unquoted keys, hex numbers)
Indentation
Formatting always emits two spaces; minified output contains no whitespace at all
Number precision
Parsed as JavaScript numbers, so integers above 2^53-1 lose precision
Key order
Preserved exactly as it appears in the input; never alphabetised
Comments
Accepted on input, but strict JSON has no comment syntax so they are dropped on output
Where it runs
Parsing, formatting and minifying all happen in your browser; the input is never sent to a server

When you would use it

  • Reading a minified API response

    Responses copied from devtools or curl arrive on one line. Formatting plus tree collapse tells you quickly whether a field exists, whether its type is right, and how many entries an array holds.

  • Putting a commented config into an env var

    JSONC files like tsconfig.json or eslintrc cannot go somewhere that only accepts strict JSON. Parse to strict JSON, then minify to one line, and it is safe to drop into a CI environment variable or a CLI argument.

  • Making a diff show only field changes

    Format both documents with the same indentation before comparing, otherwise whitespace noise swamps the real changes. From here you can hand the result straight to JSON Diff.

What to know before you start

  • Formatting only rearranges whitespace; keys, values and array order are untouched. If the output data looks different from the input, the input almost certainly had duplicate keys, and the later one wins.
  • Numbers go through JavaScript number semantics, so `1.0` comes back as `1` and snowflake-style IDs can lose their last digits. If exact digits matter, carry them as strings at the transport layer.
  • Comments in JSONC or JSON5 input disappear from the output. That is a limitation of strict JSON syntax, not the tool dropping content; keep the original file if you need the comments.
  • Everything runs in your browser. The page does not upload what you paste, and nothing remains on any server after you close the tab.

Related concepts

RFC 8259
The current JSON standard. It defines value types, string escaping and encoding requirements, and it defines no comment syntax and permits no trailing commas.
JSONC
"JSON with Comments". Adds // and /* */ comments plus trailing commas on top of JSON, mainly for editor and build-tool configuration files.
JSON5
An extension closer to ES5 literals: single-quoted strings, unquoted keys, hexadecimal numbers and multi-line strings.
Minify
Removing every unnecessary whitespace character to reach the smallest equivalent text. Lossless, and a different layer from byte-level compression such as gzip.

Frequently asked questions

Does the JSON formatter upload my data?
No. Formatting, minifying and validation all run locally in your browser, so the JSON you paste never leaves your device; safe for sensitive payloads.
Does it support JSONC and JSON5?
Yes. It parses JSONC / JSON5 with comments, trailing commas and single quotes, then re-emits standard JSON.
How do I minify JSON to a single line?
Paste your JSON and click minify to strip all whitespace and line breaks, producing compact single-line JSON for code or API payloads.
Can I collapse nested levels after formatting?
Yes. The output offers a tree view so you can expand or collapse nodes and quickly find fields inside deeply nested structures.
Why did my numbers change after formatting?
Parsing uses the JavaScript number type, which represents integers exactly only up to 2^53-1. Snowflake IDs and order numbers should travel as strings, otherwise any JavaScript-based JSON parser loses precision on them.
How large a document can this handle?
The ceiling is your browser memory, not a server quota. Tens of megabytes of text is usually fine, but the tree view slows noticeably at very high node counts; extract the subtree you need with JSONPath Query first.
Does the key order get rearranged?
No. Output keeps the key order from your input and never sorts alphabetically, so you can compare before and after line by line.