What Is JSON and How to Format & Validate It

Pageonaut · June 18, 2026

What Is JSON and How to Format & Validate It

JSON is everywhere. Web APIs return it, config files use it, and countless apps store data in it. Yet a lot of the JSON people deal with arrives as one giant unreadable line, or breaks because of a single stray comma. This guide explains what JSON is, the handful of syntax rules that govern it, the errors that bite most often, and how formatting and validation make it manageable.

What is JSON?

JSON stands for JavaScript Object Notation. It's a lightweight, text-based format for representing structured data — things like a user record, a list of products, or an app's settings. It was inspired by JavaScript object syntax, but it's now language-independent: virtually every programming language can read and write it.

Its job is to be a common, readable way to pass data between systems. When two programs need to exchange information, JSON is often the agreed-upon format because it's simple, compact and human-readable.

The syntax basics

JSON has only a few building blocks, which is why it's so widely used.

  • Objects are wrapped in curly braces and hold key/value pairs: { "name": "Ada", "age": 36 }. Keys must be strings in double quotes.
  • Arrays are ordered lists in square brackets: ["red", "green", "blue"].
  • Strings use double quotes: "hello". Single quotes are not allowed.
  • Numbers are written plainly: 42, -3.14. No quotes.
  • Booleans are true or false (lowercase, no quotes).
  • Null represents "no value": null.

Here's a small example that combines them:

{
  "title": "Pageonaut",
  "free": true,
  "tools": ["case-converter", "json-formatter"],
  "rating": 4.9,
  "owner": null
}

A few rules trip people up: keys and string values must use double quotes (not single), and there are no comments in standard JSON. Those two alone account for a surprising share of parse errors.

Common errors that break JSON

JSON is strict, which is a feature — it means there's exactly one correct way to parse a valid file. But strictness means small slips break it. The usual culprits:

  • Trailing commas. A comma after the last item is invalid: ["a", "b",] and { "x": 1, } both fail. This is probably the single most common JSON error.
  • Single quotes. 'name' is not valid; JSON requires "name".
  • Missing or extra commas. Every pair and array item needs a comma between them — and only between them.
  • Unquoted keys. { name: "Ada" } is JavaScript, not JSON. It must be { "name": "Ada" }.
  • Comments. // like this or /* this */ are not allowed in standard JSON, even though many editors tolerate them.
  • Mismatched brackets. An unclosed { or [, common after copy-pasting a fragment.

The frustrating part is that a parser usually reports only the first error it hits, so fixing one can reveal another. A validator that points to the exact line saves a lot of squinting.

Formatting vs minifying

The same JSON can be written two ways, and both are valid:

  • Formatted (pretty-printed) adds indentation and line breaks so the structure is easy to read:

    {
      "name": "Ada",
      "tools": ["json", "color"]
    }
    
  • Minified strips all unnecessary whitespace into one compact line: {"name":"Ada","tools":["json","color"]}.

They contain identical data — only the whitespace differs. Format JSON when you want to read, review or debug it. Minify it when you want the smallest possible size for sending over a network or embedding in code, where readability doesn't matter.

A common workflow is to receive a minified blob from an API, format it to understand or edit it, then minify again before using it.

Why validate?

Validating means checking that your JSON follows the rules before you rely on it. It's worth doing because:

  • It catches errors early. A malformed config or payload often fails silently or with a cryptic message deep in your code. Validating first turns that into a clear "line 12: trailing comma."
  • It confirms structure. You can verify the data has the shape you expect before passing it on.
  • It saves debugging time. Ruling out "the JSON is broken" is often the fastest first step when something downstream misbehaves.

Even a quick validation pass prevents the classic afternoon lost to a bug that turns out to be one missing quotation mark.

Format, validate and minify in one place

You don't need to scan brackets by hand. Paste your data into our free JSON Formatter to pretty-print it with clean indentation, validate it and catch errors like trailing commas, or minify it back down to one line. It runs in your browser, so your data stays on your device. You'll find more developer utilities on the tools page.

A practical routine

  1. Paste and format the JSON to see its structure.
  2. Read any validation error and fix the exact spot it points to.
  3. Repeat until it's clean — parsers report one error at a time.
  4. Minify if you need a compact version for production.

FAQ

What's the difference between JSON and a JavaScript object?

They look similar, but JSON is a strict text format: keys and strings must use double quotes, there are no comments, and trailing commas aren't allowed. A JavaScript object is more relaxed and lives in code. JSON is the portable, language-neutral version meant for storing and exchanging data.

Why does my JSON keep failing on a trailing comma?

Standard JSON forbids a comma after the last item in an object or array, even though many programming languages allow it in their own syntax. Remove the final comma in each { } and [ ] and it will parse. This is the most frequent JSON mistake by far.

Does formatting change my data?

No. Formatting and minifying only add or remove whitespace. The keys, values and structure are identical either way, so you can pretty-print and minify the same JSON back and forth without altering its meaning.

Try the tool

JSON Formatter

Open JSON Formatter