JSON Formatter & Minifier

JSON formatter and validator: beautify JSON with 2, 4 or 8 spaces, minify it to one line, see where invalid JSON fails, then copy or download.

Runs in your browser. Files never leave your device.
Valid JSON (0.21 KB)
Input JSON StringEditable
Formatted Result (beautify)Read-Only Output

About the JSON Formatter & Minifier

Paste JSON here to check it and lay it out. The formatter beautifies a minified API response with 2, 4 or 8 spaces of indentation, or minifies pretty JSON into one compact line. When the JSON is invalid, it shows the parser's error message instead, which helps when you're reading API output or editing a config file by hand.

Formatting starts as soon as you paste or type, with no button to press. When the JSON is valid you can copy the result or download it as data.json; when it isn't, the error message says what the parser expected and where. Your JSON is processed in your browser and isn't sent anywhere.

How the JSON is checked and formatted

Your input is read by the browser's own JSON parser (JSON.parse), the same strict parser web apps use to read API responses. It follows the JSON standard (RFC 8259 and ECMA-404): keys and strings in double quotes, no comments, no trailing commas, and only the values string, number, true, false, null, object and array. If the parser accepts the text, it's valid JSON.

The parsed data is then written back out with JSON.stringify. In Beautify mode each nested object and array goes on its own lines, indented by the number of spaces you pick. In Minify mode every space and line break between values is removed. Because the output is rebuilt from the data rather than edited in place, the spacing is always consistent, however messy the input was.

If parsing fails, the output panel turns red and shows the browser's error message. When the message gives only a character position, as older Chrome versions do, the tool works out the line and column and adds them, so you get, for example: Expected ',' or '}' after property value in JSON at position 20 (line 3 column 3). Firefox and Safari word their messages differently, and Safari may not give a position at all.

Valid JSON  → JSON.parse(input)
Beautify    → JSON.stringify(data, null, 2 | 4 | 8)
Minify      → JSON.stringify(data)
Size badge  → output size in UTF-8 bytes ÷ 1024, shown in KB

Assumptions and limits

  • The JSON is rebuilt from parsed data, so whole numbers above 9,007,199,254,740,991 lose precision: 12345678901234567890 comes out as 12345678901234567000. Keep large IDs as strings.
  • Numbers are written in their shortest form: 59.90 becomes 59.9 and 1e3 becomes 1000. The value is the same, but the text changes.
  • If a key appears twice in one object, only the last value is kept. Keys that are whole numbers, such as "2" and "10", are moved before the other keys in numeric order.
  • Escapes are written back in their simplest form: \u00e9 shows as é and \/ as /. The data is unchanged.
  • JSON5, JSONC and other relaxed formats aren't accepted: comments, single quotes, unquoted keys and trailing commas are errors. A byte-order mark at the start of a pasted file is ignored.
  • Everything happens in one browser tab. Files of a few megabytes usually format without delay; very large inputs can make the page slow while it works.

Worked examples

Beautify a minified API response

A 44-character response is hard to read on one line. With 2-space indentation it becomes 10 lines and 87 characters; with 4 spaces, 117; with 8 spaces, 177. Each nesting level adds one more indent.

Input:
{"user":{"id":7,"tags":["a","b"]},"ok":true}

Beautify, 2 spaces:
{
  "user": {
    "id": 7,
    "tags": [
      "a",
      "b"
    ]
  },
  "ok": true
}

Minify JSON to make it compact

Spaces inside the input add nothing for a machine. Minify reduces this 88-character order from 88 to 73 characters, about 17% smaller. Notice that 59.90 is written as 59.9.

Input:  { "order": 1042, "total": 59.90, "paid": true, "items": [ {"sku": "TS-01", "qty": 2} ] }
Minify: {"order":1042,"total":59.9,"paid":true,"items":[{"sku":"TS-01","qty":2}]}

Validate JSON and find a missing comma

A comma is missing after "Ali". The validator stops at the next key and reports line 3, column 3, which is where it expected a comma or a closing brace. Add the comma and the output appears straight away.

{
  "name": "Ali"
  "age": 30
}

Expected ',' or '}' after property value in JSON at position 20 (line 3 column 3)

Common JSON errors and how to fix them

Error wording is from Chrome; other browsers describe the same problems in their own words.

Problem in your JSONExampleFix
Trailing comma["x", "y",]Delete the comma after the last item
Single quotes{'name': 'Ali'}Use double quotes for keys and strings
Unquoted key{name: "Ali"}Put the key in double quotes
Missing comma"a": 1 "b": 2Add a comma between items
Comment{"a": 1 // note}Remove comments; JSON has none
JavaScript values{"a": undefined}, NaN, InfinityUse null, or a number or string
Unescaped quote in a string"He said "hi""Escape inner quotes as \"

How to use the JSON Formatter & Minifier

  1. Paste your JSON. Into the Input JSON String box, or clear the sample with the bin button first.
  2. Choose Beautify or Minify. For Beautify, pick 2, 4 or 8 spaces; a red panel means the JSON needs fixing.
  3. Copy or download. Copy JSON puts the result on your clipboard; Download saves it as data.json.

Frequently asked questions

How do I validate JSON online?

Paste it into the input box. If the green Valid JSON badge appears with a size, the parser accepted it. If the output panel turns red, the message underneath explains what the parser expected and, in Chrome and Edge, usually the line and column where it went wrong.

What does 'Unexpected token' mean in JSON?

The parser met a character that isn't allowed at that point. The usual causes are a trailing comma before ] or }, single quotes instead of double quotes, a comment, or a value such as undefined or NaN that exists in JavaScript but not in JSON.

Should I use 2 or 4 spaces to beautify JSON?

Either is fine: it only affects readability. Two spaces is common in JavaScript projects and keeps deep nesting on screen; four spaces suits Python projects and people who find wider indents easier to scan. Eight spaces is mainly useful for shallow data.

Does minifying JSON change the data?

No. Minify only removes the whitespace between values; every key, string and number keeps its meaning. Number formatting can change (1.50 becomes 1.5), and very large integers lose precision, so keep long IDs in quotes.

Why did the order of my keys change?

Because JavaScript always lists keys that are whole numbers, such as "1" or "2024", first and in numeric order, and a formatter built on it does the same. Other keys keep their original order. Most programs that read JSON don't depend on key order.

Is my JSON sent to a server?

No. Parsing and formatting use your browser's built-in JSON functions, so the data stays on your device. That makes it safe to format API responses containing tokens or customer data, though you should still avoid pasting secrets into shared computers.

This tool runs entirely in your browser. What you enter or upload stays on your device and is never sent to our servers.