jsonformat jsonvalidate jsonapi

What Is JSON and How to Format and Validate It Correctly

JSON guide for developers: syntax, types, common errors, how to format (pretty print) and validate JSON, and how to do it free in the browser.

June 21, 2026·6 min read

JSON is the format APIs, configs and much of the modern web speak in. It's simple, but small syntax slips cause errors that are hard to spot in a compressed single-line block. This guide explains how JSON is built, how to format it to read it and how to validate it to find the bug.

What is JSON

JSON (JavaScript Object Notation) is a text format for representing structured data. It came from JavaScript but today every language uses it. Its success comes from being human-readable and easy for machines to parse.

Supported data types:

  • String: text in double quotes → "hello"
  • Number: integer or decimal → 42, 3.14
  • Boolean: true or false
  • Null: null
  • Array: ordered list → [1, 2, 3]
  • Object: key-value pairs → { "key": "value" }

The rules most often broken

JSON is strict. These are the errors that most often break a parse:

  • Single quotes: keys and strings use double quotes, never single. 'bad'"good".
  • Trailing comma: [1, 2, 3,] is invalid. The last comma is extra.
  • Unquoted keys: { key: 1 } is JavaScript, not JSON. It must be { "key": 1 }.
  • Comments: JSON does not allow comments (// or /* */). If you need them, it's another format (JSON5, JSONC).
  • Malformed numbers: no +1, 01 or .5 (use 0.5).

Formatting JSON (pretty print)

An API response usually comes minified: everything on one line, no spaces. That saves bytes but is unreadable. Formatting (or pretty print) adds line breaks and indentation so you can read the structure:

Minified:

{"user":{"name":"Ana","roles":["admin","editor"],"active":true}}

Formatted:

{
  "user": {
    "name": "Ana",
    "roles": ["admin", "editor"],
    "active": true
  }
}

Much easier to inspect. You can format and validate free with the JSON formatter, which processes everything in your browser.

Validating JSON: finding the error

Validating means checking that the JSON follows the syntax. A good validator doesn't just say "invalid": it tells you which line and position the problem is at, which is usually an extra comma, a badly closed quote or an unmatched brace.

The typical debugging flow:

  1. Paste the JSON into the validator.
  2. If there's an error, look at the line it points to.
  3. Look for the classic problem nearby: trailing comma, single quote, unclosed brace/bracket.
  4. Fix and validate again.

Minifying JSON

The reverse of formatting: remove all spaces and indentation to reduce size. Useful when you'll send the JSON over the network or store it in a config where size matters. A single-character difference across thousands of lines adds up.

Why process it in the browser

The JSON you debug often contains real data: responses with user info, tokens, internal configs. A tool that formats and validates in your browser guarantees that data isn't uploaded to any server. It's faster and more private.

Frequently asked questions

What's the difference between formatting and validating? Formatting changes presentation (indentation); validating checks the syntax is correct. A good formatter does both.

Does JSON allow comments? No. For comments use JSON5 or JSONC, which are non-standard extensions.

Why does my JSON fail if it "looks fine"? It's almost always a trailing comma, a single quote or an unclosed brace. Use a validator that points to the line.

Is my data uploaded? No, if you use a local formatter. Everything happens in the browser.


Format, validate and minify your data instantly with the free JSON formatter, 100% in your browser and uploading nothing.

Try it without code

JSON Formatter

Format, validate and minify JSON.

Open JSON Formatter

Built by

Miguel Ángel Colorado Marin (MACM)

Full-Stack Developer · Guadalajara, España

I develop web apps, digital tools and full projects — from design to deployment.

Contact me