Developer Tool

JSON Formatter, Validator & Minifier

Format, validate, beautify and minify JSON instantly with syntax highlighting, error detection and one-click copy.

  • Free
  • No signup
  • Instant processing
  • Browser-based
  • Copy instantly

JSON Workspace

🔒 Your JSON is processed locally in your browser
JSON input
0 lines · 0 chars Tab indents · Esc frees Tab · Ctrl+Enter formats
Output
Formatted JSON will appear here.
Ready

JSON formatting, validation and minification

What is a JSON formatter?

A JSON formatter parses JSON text into a data structure and writes it back out with consistent indentation and line breaks. The data is untouched — only whitespace changes — so the formatted result is interchangeable with what you started from.

How do I format JSON?

  1. Paste your JSON into the input editor, or drop a .json file onto it.
  2. It is parsed and formatted as you type; the result appears on the right.
  3. Pick 2 spaces, 4 spaces or tabs from the indentation control.
  4. Press Copy or Download.

How do I validate JSON?

Validation runs on every change, and the Validate button reports on demand without altering the output. A valid document shows a Valid JSON status; an invalid one shows the reason, the line and column, and the offending line with a caret under the exact character.

How do I minify JSON?

Press Minify or Ctrl+Shift+M. The document is parsed first, so a compact string that does not parse can never be produced. The statistics panel reports exactly how many bytes the whitespace was costing.

Does formatting or minifying change my data?

No, in both directions. Formatting adds whitespace between tokens and minifying removes it; neither touches whitespace inside a string value, because that is data. Parse the input and parse the output and you get structures that are equal.

Why is my JSON invalid?

Almost always one of six things: a trailing comma before } or ], single quotes instead of double, an unquoted key, a missing comma between members, an unclosed bracket, or a // comment. Every one of them is legal JavaScript and none is legal JSON — which is exactly why they slip through.

JSON formatting examples

Minified and formatted

Minified
{"name":"John","age":30,"active":true}
Formatted
{
  "name": "John",
  "age": 30,
  "active": true
}

Nested objects

{
  "user": {
    "name": "John",
    "profile": {
      "age": 30
    }
  }
}

Arrays

{
  "skills": [
    "JavaScript",
    "Python",
    "PHP"
  ]
}

Invalid JSON

{
  "name": "John",
  "age": 30,
}
The last comma is the problem. After 30 the comma promises another member, and the parser then meets } instead. JavaScript object literals tolerate this; the JSON grammar does not. This tool reports it as a trailing comma rather than as a generic unexpected token.

Working with JSON

What is JSON?

JSON — JavaScript Object Notation — is a text format for structured data with exactly six value types: object, array, string, number, boolean and null. There is no date type, no comment syntax, no reference mechanism and no distinction between integers and floats. That small vocabulary is the point.

Its other defining quality is strictness. Keys must be double-quoted, commas separate members and must not trail, and there is one way to write any given structure. A JSON parser needs no configuration and cannot read the same bytes two ways, which is why JSON became the default for web APIs, log lines and configuration that machines exchange.

The same strictness makes JSON tiring to write and easy to break by hand. Almost every "invalid JSON" error comes from writing JavaScript out of habit — a trailing comma, a single quote, an unquoted key — none of which JSON accepts.

What a formatter actually does

The pipeline is short and it matters that it is done in this order: parse first, render second. The text is handed to JSON.parse, which either produces a value or throws. Only if it produces a value is anything rendered.

Doing it the other way round — manipulating the text with pattern matching to insert newlines — is how formatters end up producing output that looks indented and no longer parses. It also means such a tool cannot tell you whether your JSON was valid, because it never actually tried to read it.

Because every view here derives from one parsed value, the formatted code, the tree, the statistics and the minified copy can never disagree with one another. Change the indentation and everything re-renders from the same data.

JSON syntax rules

The complete grammar fits in a paragraph. A document is a single value. An object is zero or more "key": value pairs inside braces, separated by commas, with double-quoted keys. An array is zero or more values inside square brackets, separated by commas. A string is double-quoted, with backslash escapes for quote, backslash, slash, backspace, form feed, newline, carriage return, tab and \uXXXX. A number is an optional minus, digits, an optional fraction and an optional exponent — no leading plus, no leading zeros, no hex. And there are three bare literals: true, false and null, all lower case.

Everything else is invalid, including the things people most expect to work: comments, trailing commas, single quotes, unquoted keys, NaN, Infinity and undefined.

JSON strings, numbers and literals

Strings are where most surprises live. A literal newline cannot appear inside a JSON string — it must be written as \n — and neither can an unescaped control character. Backslashes in Windows paths must be doubled. None of that changes here: the string content you put in is the string content you get out, byte for byte.

Numbers carry a caveat worth stating plainly. JavaScript reads every JSON number as a 64-bit float, so an integer beyond 9,007,199,254,740,991 is already imprecise by the time any browser-based tool sees it. A 20-digit database identifier will come back subtly wrong — not because of this formatter, but because of how the language parses. Keep such identifiers as strings.

The three literals are exact and lower case. null stays null; it never becomes the string "null", never becomes undefined, and is never dropped from an object or an array.

Common JSON errors and how to fix them

  • Trailing comma. {"a": 1,} — remove the last comma. The single most common error, because JavaScript allows it.
  • Single quotes. {'a': 1} — JSON has only double quotes.
  • Unquoted key. {a: 1} — keys are strings and must be quoted.
  • Missing comma. Two members with nothing between them; the parser stops at the start of the second.
  • Unclosed bracket. Reported at the end of the document rather than where it opened — count from the top when the position looks wrong.
  • Comments. Not part of JSON in any form.
  • Bad escape. "\q" is not a defined escape; only a fixed set is legal.
  • Trailing content. A document holds exactly one value; anything after it is an error.

Reading a line-and-column error

The position reported is where the parser gave up, which is not always where the mistake was made. A missing closing brace is only detectable at the end of the file, so it reports there. A missing comma reports at the start of the next member, one token past the omission.

The practical technique is to read the reported line, then look at the line before it. If the reported position is the very last character of the document, you are almost certainly missing a closing bracket somewhere above. Where the cause is unambiguous — a trailing comma, a single quote, an unquoted key, a comment — this tool names it directly instead of leaving you to work it out.

Duplicate keys

A JSON object may contain the same key twice. The specification does not forbid it and simply calls the behaviour undefined, so parsers differ: JavaScript keeps the last occurrence and silently discards the earlier ones.

That silence is the problem. A configuration file with "port" written twice will do something, and it will not be what whoever wrote the first one intended. This tool detects duplicates by scanning the text — the information is gone from the parsed value — and reports the key and line, without removing anything. Which occurrence should survive is a decision about your data, not one a formatter should make for you.

Minification and payload size

Minifying JSON removes the whitespace between tokens. It is not compression, and it is worth keeping the two ideas separate: gzip or Brotli on the wire will do far more for payload size than removing indentation, and most servers already apply one of them.

Where minification does earn its place is in storage and in transports that are not compressed — a database column, a message queue payload, a query parameter, a log line. The statistics panel shows the formatted size, the minified size and the difference in bytes and per cent, calculated from your actual document rather than estimated.

Tree view

The tree is the fastest way to answer "what shape is this?" for an unfamiliar payload. Each branch names its type and member count; each leaf shows its value with the type spelled out in words next to it, so the distinction between the number 30 and the string "30" is visible rather than inferred from colour.

Clicking a leaf reveals its path — $.user.profile.name — using dot notation for identifier-safe keys and bracket notation for everything else. The filter box dims non-matching rows and opens the ancestors of every match, which is the quickest way to find where email appears in a deeply nested response.

For very large documents the tree opens collapsed. Rendering tens of thousands of nodes eagerly is the classic way a JSON viewer locks the tab, and lazily is not worth the complexity when starting collapsed solves it.

Formatting best practices

  • Two spaces is the common default and what most tooling emits. Four is easier to scan at depth; tabs let each reader choose. Be consistent within a repository.
  • Format on commit, not on read. A config file that is reformatted by whoever opened it last produces diffs full of whitespace.
  • Keep hand-edited config formatted and machine payloads minified. The audiences are different.
  • Do not sort keys in files where order carries meaning. Sorting is available here and is deliberately off by default.
  • Keep large identifiers as strings so no parser can round them.
  • If you need comments, you do not need JSON — use YAML, or a schema with a description field.

Security, and why it matters for a JSON tool

JSON is data, not code, and a formatter must treat it that way. This one never calls eval. Parsing is JSON.parse; the syntax highlighter escapes every slice of text it emits; the tree is built with createElement and textContent rather than string concatenation.

The practical result is that a document containing <img src=x onerror=alert(1)> or a <script> tag is displayed as those characters and nothing else happens. That is the correct behaviour, and it is worth checking in any tool you paste production data into.

The privacy side matters just as much. JSON pasted into a formatter is routinely an API response with a bearer token in it, or a config file with a database URL. Nothing here is uploaded: parse, format, minify and download all run in the page, and once it has loaded you can disconnect and it still works.

Frequently asked questions

What is a JSON formatter?

A JSON formatter takes JSON text, parses it into a data structure and writes it back out with consistent indentation and line breaks. The data is unchanged — only the whitespace differs — which is why the result is safe to paste back into whatever produced it.

What is JSON beautification?

Beautifying and formatting are the same operation under two names: turning compact JSON into an indented, readable layout. A minified API response on one long line becomes a document you can actually scan for the field you need.

What is a JSON validator?

A validator answers one question: is this text syntactically valid JSON? If it is not, a good validator says where the problem is. This one reports the line, the column, the reason and — where the cause is unambiguous — a hint such as "standard JSON does not allow a trailing comma".

What is a JSON minifier?

A minifier removes every space, tab and newline that sits between JSON tokens, producing the smallest text that still parses to the same data. Whitespace inside string values is part of the data and is never touched.

How do I format JSON?

Paste your JSON into the input editor. It is parsed and formatted as you type, and the result appears on the right with syntax highlighting. Choose 2 spaces, 4 spaces or tabs from the indentation control, then use Copy or Download.

How do I validate JSON?

Validation runs automatically on every change, and the Validate button reports on demand without touching the output. A valid document shows a green Valid JSON status; an invalid one shows the line, column, reason and the offending line with a caret under the exact position.

How do I minify JSON?

Press Minify, or use Ctrl+Shift+M. The document is parsed first, so minification can only succeed on valid JSON — you can never produce a compact string that does not parse. The statistics panel shows how many bytes the whitespace was costing.

What is pretty print JSON?

Pretty printing is another name for formatting: adding indentation and line breaks so the structure is visible. In JavaScript it is JSON.stringify(value, null, 2), which is exactly what this tool runs after parsing your input.

Why is my JSON invalid?

The usual causes are a trailing comma before a closing brace or bracket, single quotes instead of double quotes, unquoted object keys, a missing comma between members, an unclosed brace or bracket, or a JavaScript-style comment. All six are legal JavaScript and none are legal JSON.

How do I fix a JSON syntax error?

Start at the reported line and column. Note that an unclosed brace is usually reported at the end of the document rather than where it opened, so if the position looks wrong, count your brackets from the top. Formatting a partially fixed document often makes the remaining problem obvious.

What does "unexpected token" mean in JSON?

It means the parser found a character that cannot legally appear at that point. A stray } usually means a comma or a value is missing before it; a letter usually means an unquoted key or a bare word where a value was expected.

Why does JSON require double quotes?

Because the specification defines a string as a sequence of characters wrapped in double quotes, with no alternative. Single quotes are a JavaScript convenience that JSON deliberately left out to keep the grammar unambiguous for every language, not just JavaScript.

Are trailing commas allowed in JSON?

No. A comma after the last member of an object or array makes the document invalid, even though JavaScript accepts it. This tool detects the case specifically and tells you so rather than reporting a generic unexpected token.

Can JSON contain comments?

No. There is no comment syntax in JSON at all — neither // nor /* */. Formats that allow them, such as JSON5 and JSONC, are separate specifications. If you need comments in configuration, YAML is usually the better choice.

What is the difference between JSON and JSON5?

JSON5 is a superset that adds comments, trailing commas, single-quoted strings, unquoted keys and a few number forms. It is a different format with its own parsers. This tool processes standard JSON only, so a JSON5 document is reported as invalid rather than silently accepted.

Can this tool format large JSON files?

Yes. Formatting and analysis are linear in document size and a file with tens of thousands of records completes in well under a second. For very large input the live pass is debounced longer, syntax highlighting is skipped and the tree starts collapsed so the first paint stays fast.

Can I format API responses?

Yes, and it is the most common use. Paste a minified response straight from your network tab or a curl command. Because everything runs locally, a response containing a token or personal data never leaves your machine.

Can I download formatted JSON?

Yes. Download saves exactly what is in the output pane as formatted.json, or minified.json if you last minified. It is generated in the browser with a Blob and there is no upload step.

Can I copy minified JSON?

Yes. Copy minified produces the compact form from the same parsed data without changing what is displayed, so you can keep reading the formatted version while pasting the compact one.

Does formatting change JSON data?

No. Formatting only adds whitespace between tokens. Every key, value, type and array order is identical, and parsing the formatted output gives a structure equal to parsing the original.

Does minification change JSON data?

No. Minification removes whitespace between tokens only. Spaces, tabs and newlines inside string values are part of the data and are preserved exactly.

What is the difference between formatting and validating JSON?

Validating asks whether the text is legal JSON and answers yes or no. Formatting rewrites valid JSON into a readable layout. Formatting implies validation — a document has to parse before it can be reformatted — but validating on its own leaves the text untouched.

Can JSON contain arrays?

Yes. An array is an ordered list in square brackets and may hold any mix of values, including other arrays and objects. Order is significant and is always preserved by this tool, including when key sorting is switched on.

Can JSON contain nested objects?

Yes, to any depth. The statistics panel reports the maximum depth of your document, and the tree view lets you collapse branches you are not interested in.

How are null values handled?

null is preserved as the JSON literal null. It is never turned into the string "null", into undefined, or into an empty string, and it is never silently dropped from an object or an array.

How are booleans handled?

true and false are preserved as literals. A string containing the text "true" is different data and stays a quoted string, so the two can never be confused.

Can JSON contain Unicode?

Yes. Devanagari, Chinese, Japanese, Arabic, accented Latin and emoji all pass through unchanged. There is an optional Escape Unicode setting that rewrites them as \uXXXX sequences — a change of representation, not of the underlying text — and it is off by default.

How are large numbers handled?

JavaScript reads every JSON number as a 64-bit float, so an integer beyond 9,007,199,254,740,991 loses precision during parsing — in this tool and in every other browser-based one. If your data contains large identifiers, keep them as strings in the JSON.

What happens to duplicate keys?

They are detected and reported with the key name and line number, and nothing is removed for you. JSON parsers keep the last occurrence and discard earlier ones, so a duplicate usually means data is being lost silently somewhere upstream — which is worth knowing about rather than having quietly cleaned up.

What is JSON tree view?

A collapsible outline of the parsed document. Each branch shows its type and how many members it has, each leaf shows its value and type in words as well as colour, and clicking a leaf reveals its path such as $.user.profile.name.

Does sorting keys change my data?

It changes the order properties appear in, which some systems care about, so it is off by default. The values themselves are untouched and array order is never altered.

Is JSON formatting safe?

Yes, when the tool treats JSON as data rather than code. This one parses with JSON.parse, never eval, and every character it displays — including the syntax highlighter and the tree — is escaped or inserted as text, so a document containing HTML or a script tag is shown, not run.

Is my JSON uploaded to a server?

No. Parsing, formatting, minifying and downloading all happen in your browser and no network request carries your data. This matters because JSON pasted into a formatter routinely contains API keys, tokens and personal data.

Is this JSON formatter free?

Yes. Free, no sign-up, no email address and no limit on document size beyond what your browser can hold.

Other ToolAdda converters and formatters that run entirely in your browser.

This formatter runs entirely in your browser. Your JSON is parsed with JSON.parse — never eval — no network request carries your data, nothing is logged, and the document is gone when you close the tab. Formatting and minifying change whitespace only; the parsed data is identical either way.