Skip to main content

Format JSON Online: JSON Formatter & Validator

Format, validate and minify JSON, with clear error messages for invalid input.

Built and tested by Muhammad Irfan Liaqat · Updated

Indent:

JSON Formatter: key facts

  • Formats (pretty-prints) JSON with 2- or 4-space indentation, or minifies it to one line
  • Validates strictly: invalid JSON shows the browser's error message instead of output
  • Keeps keys in their original order and does not change any values
  • Paste-in only; the JSON stays in your browser

How JSON formatting and validation work

Paste JSON into the formatter to re-indent it into readable, nested lines, or minify it into a single compact line. If the input is not valid JSON, you get your browser's parser error instead, which points to the problem, such as a missing comma, an unclosed bracket or a trailing comma.

Formatting normally changes only whitespace; the section below lists the few cases where values or key order change. Choose 2-space or 4-space indentation to match your project's style. Strict JSON is less forgiving than JavaScript: keys and strings need double quotes, trailing commas are not allowed and comments are not part of the format, so an object that works in JavaScript code can still fail here. Parsing happens in your browser, so API responses and config files containing tokens are not sent anywhere.

How to format and validate JSON

  1. 1Paste or type JSON into the input box
  2. 2Choose 2 or 4 spaces of indentation
  3. 3Click Format to beautify the JSON, or Minify to compress it
  4. 4Fix any error shown, then click Copy to copy the result

Common JSON errors and how to fix them

ProblemInvalidValid
Trailing comma after the last item{"a": 1,}{"a": 1}
Single quotes{'a': 'x'}{"a": "x"}
Key without quotes{a: 1}{"a": 1}
Comment{"a": 1 // note}{"a": 1}
JavaScript-only values{"a": undefined, "b": NaN}{"a": null, "b": null}
Line break or quote inside a string{"a": "say "hi""}{"a": "say \"hi\""}

Browsers word their error messages differently, but most give the position where parsing stopped. The real mistake is usually just before that point.

When formatting changes more than whitespace

The formatter reads your JSON into memory and writes it out again, which is the same thing most programs do with it, so a few details can change. Numbers beyond 9,007,199,254,740,991 lose precision: an ID of 12345678901234567890 comes back as 12345678901234567000. If your data has IDs that large, the API should send them as strings.

Duplicate keys are not an error, but only the last value is kept, so {"a": 1, "a": 2} becomes {"a": 2}. Keys that are whole numbers move to the front in numeric order. Numbers are written in their shortest form, so 1.0 becomes 1 and 1e3 becomes 1000, and escape codes such as \u00e9 are shown as the character é. None of these changes the meaning for a standard JSON parser, but they matter if you compare files line by line.

Frequently Asked Questions

What is JSON format?
JSON (JavaScript Object Notation) is a plain-text format for structured data, defined in RFC 8259. It has six kinds of value: objects in { }, arrays in [ ], strings in double quotes, numbers, true or false, and null. For example, {"name": "Ana", "age": 31, "tags": ["admin"]} is valid JSON. Most web APIs send and receive data in this format.
What does a JSON formatter do?
It adds line breaks and indentation so that nested objects and arrays are easy to read, without changing any data. Minifying does the opposite and removes all optional whitespace.
Why is my JSON invalid?
The most common causes are single quotes instead of double quotes, keys without quotes, a trailing comma after the last item, a missing comma between items, comments, and unclosed brackets or braces. The error message tells you where the parser stopped.
What is the difference between [ ] and { } in JSON?
Curly braces define an object, a set of named keys and values such as {"name": "Ana"}. Square brackets define an array, an ordered list such as ["red", "blue"]. Either can contain the other.
Can I minify JSON?
Yes. Minify removes spaces and line breaks to produce the smallest valid JSON, which is useful for API payloads and storage.
Is my data safe here?
Yes. The JSON is parsed in your browser and never sent to a server, logged or stored.
How do I check whether my JSON is valid?
Paste it in and press Format. Valid JSON is formatted in the output box; invalid JSON shows an error message, which in most browsers includes the position of the problem.
Does it accept comments or trailing commas?
No. Standard JSON allows neither, so both cause an error. Remove the comments and the comma after the last item in each object or array.
Can it fix broken JSON automatically?
No. It tells you that the JSON is invalid and where parsing stopped, and you fix it by hand. The usual culprits are single quotes, missing quotes around keys, trailing commas and unescaped line breaks inside strings.

Related Tools

Guides