Webtools

JSON Formatter

Format, validate, and minify JSON with syntax highlighting

What is a JSON formatter?

A JSON formatter — also called a JSON pretty-printer or beautifier — takes raw or minified JSON and re-emits it with consistent indentation and line breaks so a human can read and inspect it. This tool validates the input against the IETF RFC 8259 JSON specification, formats valid input with two-space indentation and one element per line, and reports the position of the first syntax error when the input is malformed. It also offers a Minify mode that strips all non-essential whitespace, producing the smallest possible representation for transmission or storage.

JSON is the lingua franca of HTTP APIs, configuration files, and structured logs in 2026. The strict spec — published as RFC 8259 in 2017 to supersede the older ECMA-404 — defines six value types (object, array, string, number, boolean, null), a precise grammar for each, and zero tolerance for comments, trailing commas, single-quoted strings, or unquoted property names. The strictness is deliberate: it makes JSON cheap to parse in any language and unambiguous to round-trip across systems. The cost is that a tiny error — a stray comma, a curly quote pasted from a word processor — invalidates the entire document, which is why a formatter that points to the offending position is far more useful than one that just rejects the input.

Developers reach for a JSON formatter dozens of times a day: inspecting an API response in a network tab, debugging a webhook payload, formatting a config file before committing it, or minifying JSON before embedding it in a query string or HTML attribute. This tool runs entirely in the browser using JavaScript's built-in JSON.parse() and JSON.stringify() — the same parser the language ships with — so the formatting matches the strictness of the JSON spec exactly, and the data you paste in never leaves your device.

Format, Minify, Validate — what each mode does

The three modes the tool offers do related but distinct things. Picking the right one depends on whether you want JSON for human reading, machine transmission, or pure error-checking.

Format (pretty-print)

with indentation

Parses the input as JSON and re-emits it with two-space indentation, one property or array element per line, and consistent spacing around : and ,. The semantic content is unchanged — only whitespace differs. This is the form you want when reading an API response, comparing two payloads in a diff tool, or committing a config file to version control.

Minify (compact)

single line

Strips all whitespace that the JSON spec does not require, producing the smallest representation that still parses. A typical formatted document shrinks 20–60% when minified. Use this form when transmitting JSON over a network where every byte matters, embedding it in an HTML attribute or query string, or storing it in a database column where the size affects index performance.

Validate

check only

Parses the input and reports whether it is valid JSON, including the line and column of the first error. Validation is also performed implicitly by Format and Minify — if the input cannot be parsed, neither mode produces output. The validator follows RFC 8259 strictly: comments, trailing commas, unquoted keys, single-quoted strings, hexadecimal numbers, and JavaScript-style identifiers all fail.

Trailing commas

[1, 2, 3,]

A trailing comma after the last element of an array or object is valid in modern JavaScript, Python, and most config languages — but invalid in JSON. The error message points to the comma. Remove it (or use a JSON5/JSONC parser if you control the consumer).

Comments

// not allowed

Neither // line nor /* block */ comments are valid JSON. If you need comments in a config file, use JSONC (Visual Studio Code's superset, used in tsconfig.json), JSON5, YAML, or TOML. Some teams use a top-level "_comment" key as a workaround inside strict JSON.

Number precision

0.1 + 0.2

JSON numbers are an unbounded decimal grammar — but JavaScript and most parsers convert them to IEEE 754 double-precision floats, which only safely represent integers up to 2^53 - 1 (about 9 quadrillion) and lose precision for many decimals. If your data includes 64-bit IDs or precise monetary values, transmit them as strings and parse on the consumer side.

Encoding

UTF-8 only

RFC 8259 mandates UTF-8 for any JSON exchanged between systems. JSON strings can include any Unicode character either directly (as UTF-8 bytes) or escaped via \uXXXX. Non-BMP characters require a UTF-16 surrogate pair — "\uD83D\uDE00" for 😀. JSON.stringify picks the form that produces the shortest output by default.

JSON-family formats compared

Several "JSON-like" formats exist, each adding features that strict JSON omits. The table below summarises which format adds what, and which tools and contexts use each one. Stick to strict JSON for anything sent over the wire to an arbitrary consumer.

Format Adds over JSON Used by
Strict JSON (RFC 8259) — (the baseline) HTTP APIs, package.json, most file formats
JSONC (JSON with Comments) comments, trailing commas Visual Studio Code, tsconfig.json, TypeScript
JSON5 comments, trailing commas, unquoted keys, single quotes, hex numbers Babel config, some npm tools
NDJSON / JSON Lines one document per line log files, streaming pipelines, BigQuery, Spark
JSON Schema schema language for validation OpenAPI, AJV, JSON-validating libraries
JSONP (legacy) function-call wrapper for cross-origin pre-CORS browser APIs (now obsolete)
HJSON comments, multiline strings, optional commas human-edited config files
YAML comments, references, complex types, indentation-sensitive syntax Kubernetes, GitHub Actions, Ansible
TOML comments, datetimes, sectioned tables Rust Cargo, Python pyproject.toml, Hugo
BSON binary encoding, extra types (date, ObjectId) MongoDB wire protocol and storage
MessagePack binary encoding, smaller payload Redis, distributed caches, IPC
CBOR binary encoding (RFC 8949), self-describing COSE, WebAuthn, IoT protocols

How parsing and pretty-printing work

JSON parsing is one of the simplest grammars to implement: a recursive-descent parser is roughly 200 lines of code. The grammar is unambiguous and context-free — every input either matches the spec or it does not. This tool delegates to JavaScript's built-in JSON.parse(input), which throws a SyntaxError with a position when parsing fails; that position is what the error message reports. Pretty-printing then calls JSON.stringify(value, null, 2), where the third argument is the indentation level — passing 2 indents nested structures by two spaces per level, while passing null or omitting it produces a single compact line, which is what Minify uses. Property order is preserved as written; arrays preserve element order. The parsing and serialisation use the same UTF-16 string handling as the rest of JavaScript, so non-ASCII characters round-trip without modification.

Frequently asked questions

What's the difference between Format and Minify?
Format adds indentation and line breaks to make JSON human-readable; Minify removes all non-essential whitespace to produce the smallest possible representation. The semantic content is identical between the two — only whitespace differs. Format is what you want for reading, debugging, and committing to version control; Minify is what you want for transmitting over a network or embedding in a query string.
Is my JSON data sent to a server?
No. All formatting, minification, and validation happens in your browser using JavaScript's built-in JSON.parse() and JSON.stringify(). Your input never leaves your device, and the tool works offline once the page has loaded.
Why does my JSON have a "parse error" when it looks fine?
The most common causes: a trailing comma after the last element of an array or object (legal in JavaScript and Python, illegal in JSON), single-quoted strings instead of double-quoted (JSON requires double quotes), unquoted property keys, comments (JSON does not allow them), or curly-quote characters pasted from a word processor (" instead of "). The error message points to the position of the first problem.
Can JSON contain comments?
Strict JSON cannot. If you need comments in a config file, options are: JSONC (used by Visual Studio Code in tsconfig.json), JSON5, YAML, or TOML. A common workaround inside strict JSON is to use a "_comment" key — every parser accepts it, but it is not a real solution.
What's the largest number JSON can represent precisely?
JSON's number grammar is unbounded — but JavaScript and most parsers convert numbers to IEEE 754 double-precision floats, which can precisely represent integers up to 2^53 - 1 = 9,007,199,254,740,991. Larger integers (64-bit IDs, blockchain values, scientific notation) silently lose precision when parsed. The standard workaround is to transmit such values as strings and parse them on the consumer side as a BigInt or arbitrary-precision number.
What encoding does JSON use?
RFC 8259 mandates UTF-8 for JSON exchanged between systems. JSON strings can include any Unicode character either directly as UTF-8 bytes or escaped via \uXXXX. Characters outside the Basic Multilingual Plane (most modern emoji) require a UTF-16 surrogate pair: 😀 is "\uD83D\uDE00" in escaped form, or four UTF-8 bytes when written directly.
How do I include a literal quote, backslash, or newline in a JSON string?
JSON requires escapes: \" for a double quote, \\ for a backslash, \n for a newline, \t for a tab, \r for a carriage return, and \uXXXX for any Unicode character by codepoint. Forward slashes / may optionally be escaped as \/, but it is not required.
Should I use JSON or YAML / TOML for config files?
Use JSON when the file is machine-generated or machine-consumed (npm package.json, build manifests, API responses). Use JSONC when you want JSON-with-comments and your tooling supports it (TypeScript, VS Code). Use YAML when humans edit the file frequently and the structure is deeply nested (Kubernetes, GitHub Actions). Use TOML when humans edit the file frequently and the structure is mostly flat with sections (Cargo, pyproject.toml). All four are interconvertible.

Related tools

Base64 Encoder
Encode and decode Base64 strings
URL Encoder
URL encode and decode strings
JWT Decoder
Decode JWT tokens and inspect header, payload, and signature
UUID Generator
Generate UUIDs v4 and v7 in bulk
Browse other categories: Word Tools· Number Tools· Text Tools· Converters· Color Tools· Time Tools· Random Generators