Skip to main content
JF

JSON Formatter & Validator

Format, minify, or validate JSON instantly — with syntax highlighting, right in your browser.

Did you like the tool? Thanks!
Share:


    

How to Use JSON Formatter & Validator

Paste JSON into the box and click "Format" for a readable, indented, syntax-highlighted version, "Minify" to strip it down to the smallest valid single-line form, or "Validate" to check it is well-formed without producing any output. Nothing you paste is uploaded — parsing happens entirely in JavaScript on your device.

About JSON Formatter & Validator

JSON (JavaScript Object Notation) is the de facto data-interchange format of the modern web — REST APIs, configuration files, log entries, and the payloads passed between almost every frontend and backend all use it. Its two biggest practical problems are also its biggest strengths taken too far: because whitespace is optional, a JSON payload can be minified down to the smallest possible number of bytes for transmission, but that same minified form is nearly unreadable to a human trying to debug what an API actually returned. This tool solves both directions of that problem with one paste box. Format takes any valid JSON and re-serializes it with 2-space indentation and one key or array element per line, which is the layout most style guides and most editors default to. It also applies lightweight syntax highlighting — strings in green, keys in purple, numbers in blue, booleans in orange, and null in grey — using a plain regular-expression tokenizer rather than a heavyweight syntax-highlighting library, so the page stays fast even on large payloads. Minify does the opposite: it strips every unnecessary space, tab and newline, producing the smallest valid representation of the same data, which is exactly what you want before pasting a payload into a size-constrained field (a URL query parameter, a database column with a length limit, a request body you are trying to keep under a size threshold). Validate is a dedicated third mode for when you only want a yes/no answer plus a location, without needing to see reformatted output. It reports the browser's own `JSON.parse` error message, which — since Chrome 116/Firefox 119 era engines — typically includes the line and column of the first problem (for example, a trailing comma, an unquoted key, or a missing closing brace). That built-in error message is written by the same engine that will eventually consume the JSON in a real application, so it is a more reliable signal than a third-party linter that might parse JSON slightly differently. A common point of confusion: JSON is stricter than JavaScript object literal syntax, even though it looks almost identical. Trailing commas after the last item in an array or object are invalid in JSON (they are allowed in modern JavaScript), keys must always be double-quoted strings (single quotes and unquoted keys are both invalid), and comments are not permitted anywhere in a JSON document, even though many JavaScript-adjacent config formats (JSON5, JSONC used by VS Code's settings files) do allow them. If your input fails validation and looks correct at a glance, checking for these three things first — trailing commas, unquoted/single-quoted keys, and stray comments — resolves the large majority of "but this looks fine" JSON errors. Because everything runs client-side, this tool is safe to use on real API responses and configuration files that may contain access tokens, internal URLs or other sensitive values you would not want to paste into a third-party server — nothing you type here is transmitted, logged, or stored.

Details & Tips

What Format does: parses the input with `JSON.parse`, then re-serializes it with `JSON.stringify(value, null, 2)` — 2-space indentation, one key/element per line, with syntax highlighting applied to the result for readability. What Minify does: parses the input the same way, then re-serializes with `JSON.stringify(value)` (no indentation argument), producing the shortest valid single-line JSON representation of the same data — useful before pasting into space-constrained fields, or for reducing payload size before transmission. What Validate does: attempts to parse the input and reports either "Valid JSON" or the exact parser error message (including line/column position on modern browsers) without producing any formatted output — a quick yes/no check. Common validation errors and their fix: • Trailing comma after the last array/object item (`[1, 2, 3,]`) → remove the final comma; JSON, unlike JavaScript, does not allow it. • Unquoted or single-quoted keys (`{name: "x"}` or `{'name': "x"}`) → all keys must be double-quoted strings (`{"name": "x"}`). • Comments (`// ...` or `/* ... */`) anywhere in the document → JSON has no comment syntax at all; strip them before validating (this is a common gotcha when copying from a JSONC/JSON5 config file like VS Code's `settings.json`). • A stray trailing character after the closing brace/bracket (e.g. a semicolon left over from a `const data = {...};` JavaScript assignment) → JSON must be exactly one value, nothing before or after it. • Using `NaN`, `Infinity`, or `undefined` as a value → none of these are valid JSON tokens, even though they are valid JavaScript expressions; use `null` or a string instead. Syntax highlighting colors used in the output: strings and array/object values in green, object keys in purple, numbers in blue, `true`/`false` in orange, `null` in grey — implemented as a single regular expression over the already-formatted text, not a full tokenizing parser, so it stays fast even on multi-thousand-line payloads. Tip: to quickly check whether two JSON payloads represent the same data despite different key ordering or whitespace, Format both of them separately with consistent indentation and compare — most editors' diff view will then only show genuine content differences rather than noise from formatting.

Frequently Asked Questions

What is the difference between Format and Minify?
Format adds 2-space indentation and line breaks to make JSON easy to read, while Minify strips all unnecessary whitespace to produce the smallest valid representation — useful before sending the data over a network or into a size-limited field.
Why does Validate say my JSON is invalid when it looks correct?
The three most common causes are a trailing comma after the last item, single-quoted or unquoted object keys (JSON requires double quotes), and comments — none of these are valid JSON syntax even though similar-looking formats (like JavaScript object literals or JSON5) allow them.
Is my JSON data uploaded to a server?
No. All formatting, minifying and validation happens locally in your browser using JavaScript. Nothing you paste is transmitted, logged, or stored, so it is safe to use with real API responses containing tokens or internal data.
Can this tool handle very large JSON files?
Yes, within the limits of your browser tab's memory — the parser is the browser's native `JSON.parse`, the same engine used by real applications, so it handles large payloads efficiently. Extremely large files (tens of megabytes) may feel slower to render with syntax highlighting.
Does trailing-comma or comment support ever get added?
No — this tool validates strict JSON as defined by the JSON specification (RFC 8259), the same standard every JSON parser and API expects. If you need to work with JSON5 or JSONC (which allow comments and trailing commas), use a tool built for those specific formats instead.
Why are object keys shown in a different color than string values?
The syntax highlighter distinguishes keys (purple) from string values (green) to make nested structures easier to scan visually — both are technically JSON strings, but they play different roles in the data.
Can I copy the formatted or minified output?
Yes, a Copy button appears once a result is produced and copies the exact output text to your clipboard.
Does Format change the order of my object keys?
No. JavaScript's `JSON.stringify` preserves the original key insertion order (for string keys) exactly as it was in the parsed object — it does not alphabetize or reorder keys.
What happens to numbers with many decimal places?
They are preserved exactly as JavaScript's native number parsing represents them. Extremely high-precision decimal numbers beyond what a 64-bit floating point number can represent exactly may lose precision, which is a limitation of the JSON/JavaScript number type itself, not this tool.
Can I validate JSON that starts with an array instead of an object?
Yes. Valid JSON documents can have any JSON value — object, array, string, number, boolean, or null — as their top-level value, and all of these are accepted by Format, Minify and Validate.
Why is there no "beautify with tabs instead of spaces" option?
2-space indentation is used consistently across every formatter tool in this category (matching common style guides like the JSON style used by most linters), keeping output predictable regardless of which tool on the site produced it.

Also Available As

json formatter, json validator, json minifier, json beautifier, format json online, json pretty print, json linter, json syntax checker

Found a Problem?

Let us know if something with JSON Formatter & Validator isn't working as expected.

Thanks — we'll take a look.