JSON Formatter
Format, minify, or validate JSON locally in your browser with 2- or 4-space indentation, so sensitive API payloads never leave the tab.
What it does
- Pretty-print JSON with 2 or 4-space indentation
- Minify JSON to a single line
- Validate syntax with the exact line and column of the error
- Strict RFC 8259 parsing by a Rust (serde_json) engine
- Runs via WebAssembly, no data sent externally
This JSON formatter takes a raw or minified JSON document and does one of three things with it: pretty-prints it with 2 or 4 spaces of indentation, minifies it to a single line, or validates it and tells you exactly where the syntax breaks. Parsing runs in serde_json, the standard Rust JSON library, compiled to WebAssembly and executed inside your browser tab. API payloads often carry bearer tokens or internal field names, and as the JSON formatting guide puts it: if the sample should stay private, the formatter should stay local.
How to format JSON
- Paste your JSON into the input box. It can be a single line copied from a log, a response body from your browser's Network tab, or a whole configuration file.
- Pick the indentation:
2spaces (the default, common in JavaScript and web projects) or4spaces (common in Python and many style guides). - Click Format for readable output, Minify for a compact single line, or Validate to check syntax only.
- Copy the result with the copy button next to the output.
The three modes and when to use each
- Format: re-serializes the document with consistent indentation and one key per line. Use it to read an API response, review a config change, or paste a readable sample into a ticket or documentation.
- Minify: removes every insignificant space and line break. The status line shows the resulting character count. Use it to embed JSON in an environment variable, a query parameter, a test fixture, or anywhere a single line is required.
- Validate: parses without producing output and reports either "Valid JSON" or the first error, with its line and column (for example
Error at line 1, column 8: trailing comma). Use it when a deployment or a parser rejects a file and you need the exact position of the problem.
What the formatter changes in your JSON
The tool parses the document into a data structure and writes it back out. That is what guarantees valid output, but it also means a few things are normalized rather than preserved character for character:
- Key order: object keys come out sorted alphabetically, at every level of nesting. Arrays keep their order. JSON objects are unordered by specification, so this does not change the meaning, but a diff against the original file will show moved lines.
- Duplicate keys: if an object contains the same key twice, the last value wins and only one key remains in the output.
- Very large integers: integers beyond the 64-bit range are converted to floating point and lose precision (for example a 23-digit ID becomes
1.2345678901234568e+22). Integers within the 64-bit range and decimals such as1.0are kept as written. If your IDs are longer, store them as strings. - Whitespace inside strings is never touched. Only the whitespace between tokens is rewritten.
Common JSON errors the validator catches
The parser is strict and follows the JSON standard, so it rejects the syntax that JavaScript or configuration dialects tolerate but real JSON does not:
- Trailing commas after the last item of an object or array.
- Comments (
//or/* */), which are not part of JSON. Files such astsconfig.jsonuse the JSONC dialect and will not validate here until the comments are removed. - Single-quoted strings or unquoted keys, which are JavaScript object syntax, not JSON.
- Unescaped control characters or line breaks inside a string.
- Missing commas between items, or a missing closing bracket at the end of a truncated response.
The error message gives the line and column where parsing stopped. The real mistake is usually at that position or just before it, for example a missing comma on the previous line.
Compared with an editor or the command line
If you have jq installed, jq . does the same pretty-printing in a terminal, and python -m json.tool works wherever Python is available. Code editors such as VS Code format JSON with a keyboard shortcut. This page is useful when you are on a machine without those tools, when you need the line and column of an error quickly, or when you want to share a link to a formatter with a colleague without asking them to install anything. Unlike most web formatters, it does not send the pasted text to a backend.
Privacy: why format JSON locally
JSON is the format that carries API keys, session tokens, user records, internal hostnames and database credentials. Pasting a production response into a formatter that posts it to a server means that data now sits in someone else's logs. Here, the parsing and formatting run in WebAssembly inside the page, with no network request made for your input. You can confirm it in your browser's Network tab, or load the page and then disconnect from the internet: the formatter keeps working.
Frequently asked questions
- Is my JSON sent to a server?
- No. The JSON is parsed and formatted by a Rust module compiled to WebAssembly that runs in your browser tab. Nothing is uploaded, logged or stored.
- Why did the order of my keys change?
- The formatter rebuilds the document from its parsed data, and objects are written with keys sorted alphabetically. The data is equivalent, since JSON does not give object keys a meaningful order, but if you need the original order preserved for a line-by-line diff, compare minified versions or keep the source file as reference.
- Does the validator accept comments or trailing commas?
- No. It validates standard JSON only. Comments and trailing commas produce an error with the line and column, which is the same behavior you get from most production parsers.
- What is the difference between 2 and 4-space indentation?
- Only readability and convention. Both produce valid JSON with identical data. Use whichever matches the style of the project the file belongs to.
- Can it fix invalid JSON automatically?
- No. It reports the first error and its position so you can fix it yourself. Automatic repair would have to guess your intent, for example where a missing bracket belongs.
- Is there a size limit?
- There is no fixed limit. Formatting happens in memory, so very large documents (tens of megabytes) depend on your device's available memory and may take a moment.
- Can I convert JSON to another format here?
- This tool keeps JSON as JSON. To turn a JSON array into a spreadsheet, use the JSON to CSV converter. To produce configuration files, use the JSON to YAML converter.
Related tools: compare two versions of a formatted file line by line with the text diff tool, or convert between configuration formats with the YAML, JSON and TOML converter.