How to Format & Validate JSON Online β€” Free Tool + Guide

What Is JSON and Why Does Formatting Matter?

JSON (JavaScript Object Notation) is the lingua franca of modern web APIs. It's what your weather app reads when it checks the forecast, what Stripe returns when you create a payment, and what your config files store when they don't have a better format. JSON is simple by design β€” just keys, values, arrays, and objects β€” but a single syntax error makes it completely unreadable by parsers.

Unformatted JSON looks like this:

{"name":"Alice","age":30,"active":true,"scores":[95,87,92],"address":{"city":"Portland","zip":"97201"}}

That's valid, but good luck reading it when the object has 40 keys and 5 levels of nesting. Pretty-printed JSON with consistent indentation is the difference between a debugging session that takes 2 minutes and one that takes 20.

Format JSON Instantly β€” No Install Required

Paste your JSON, click Format, and get clean, indented output with syntax validation. Runs entirely in your browser.

Open JSON Formatter β†’

JSON Syntax: The Six Rules

JSON has six data types and a small set of rules. Break any of them and the parser throws an error β€” often without telling you exactly where the problem is.

TypeExampleNotes
String"hello"Must use double quotes. Single quotes are invalid.
Number42, 3.14, -7No leading zeros. No NaN or Infinity.
Booleantrue, falseLowercase only. Not True or TRUE.
NullnullLowercase only.
Array[1, 2, 3]Ordered list of any types.
Object{"key": "value"}Unordered key/value pairs. Keys must be strings.

The 7 Most Common JSON Errors

1. Trailing Commas

This is the most frequent JSON mistake:

{
  "name": "Alice",
  "age": 30,      ← trailing comma β€” invalid JSON
}

JSON does not allow a comma after the last item in an object or array. JavaScript and many config parsers accept this (it's valid in JS), which is why it catches people off guard. JSON proper does not.

2. Single Quotes

{'name': 'Alice'}  ← invalid
{"name": "Alice"}  ← valid

JSON requires double quotes for all strings, including keys. Single quotes are JavaScript syntax, not JSON syntax.

3. Comments

{
  // This is invalid JSON
  "name": "Alice"
}

JSON has no comment syntax. No //, no /* */. If you need commented config files, use TOML or YAML instead. Some tools support JSON5 (a superset that adds comments), but standard JSON parsers will reject them.

4. Unescaped Special Characters in Strings

Certain characters inside strings must be escaped with a backslash: double quote (\"), backslash (\\), newline (\n), tab (\t), carriage return (\r). A raw newline inside a string value is invalid JSON.

5. Keys Without Quotes

{name: "Alice"}     ← invalid (JavaScript object literal, not JSON)
{"name": "Alice"}   ← valid

In JavaScript, object keys don't need quotes if they're valid identifiers. In JSON, keys must always be quoted strings. This is one of the most common copy-paste errors when going from JS code to a JSON file.

6. Undefined Values

JavaScript's undefined is not a valid JSON type. If you serialize a JavaScript object with undefined values using JSON.stringify(), those keys are silently dropped. If you try to include undefined literally in JSON, the parser will throw.

7. Numbers with Leading Zeros

{"zip": 07201}   ← invalid
{"zip": "07201"} ← valid (as string)
{"zip": 7201}    ← valid (as number, loses the leading zero)

ZIP codes, phone numbers, and any numeric data where leading zeros matter should be stored as strings in JSON.

Pretty-Printing vs. Minifying: When to Use Each

Pretty-Print (Formatted) JSON

Use formatted JSON when:

The cost of pretty-printing is file size. A well-indented JSON file can be 30–50% larger than its minified equivalent due to whitespace.

Minified JSON

Use minified JSON when:

Most production APIs serve minified JSON. If you're building an API that returns large payloads, consider gzip compression on top β€” gzip typically reduces JSON by 70–80% regardless of whether it's pretty-printed or minified, because JSON's repetitive structure compresses exceptionally well.

When to Validate JSON

Validation catches syntax errors before they cause runtime failures. You should validate JSON whenever:

A good online JSON formatter does two things simultaneously: it formats and it validates. If the input is invalid, it tells you why and where (line number, expected token). This is faster than reading a stack trace from your parser.

Validate & Format Your JSON Now

Paste minified or messy JSON and get clean, indented output with error detection. Completely free, no account needed.

Open JSON Formatter β†’

JSON vs. Related Formats

FormatBest ForAllows Comments?Strict?
JSONAPIs, data exchangeNoYes
JSON5Config filesYesNo
JSONCVSCode configYesNo
YAMLConfig files, CI pipelinesYesNo (whitespace-sensitive)
TOMLRust/Python configYesYes
XMLEnterprise data, SOAPYesYes

Related Articles