DEV Community

Cover image for A developer's guide to JSON — formatting, validation, and common mistakes
William Andrews
William Andrews

Posted on

A developer's guide to JSON — formatting, validation, and common mistakes

JSON is everywhere.

It's the format your API returns data in. It's your config files,
your package.json, your database exports, your webhook payloads.
If you write code that talks to anything else, you're working
with JSON every single day.

And yet it trips developers up constantly — not because it's
complicated, but because it's unforgiving. One missing comma,
one extra bracket, one set of single quotes instead of double,
and the whole thing breaks.

This guide covers what you actually need to know.

What JSON is and why it matters

JSON stands for JavaScript Object Notation. It was designed to
be lightweight, human-readable, and easy for machines to parse.
It succeeded on all three counts, which is why it became the
default data format for APIs and web services.

A JSON object looks like this:

{
  "name": "DevCrate",
  "tools": 12,
  "private": true,
  "url": "https://devcrate.net"
}
Enter fullscreen mode Exit fullscreen mode

Keys are always strings wrapped in double quotes. Values can be
strings, numbers, booleans, arrays, objects, or null. That's it.
The whole spec fits on one page.

Why formatting matters

Minified JSON is fast to transmit but impossible to read:

{"name":"DevCrate","tools":12,"private":true,"url":"https://devcrate.net"}
Enter fullscreen mode Exit fullscreen mode

Formatted JSON is slower to transmit but immediately readable:

{
  "name": "DevCrate",
  "tools": 12,
  "private": true,
  "url": "https://devcrate.net"
}
Enter fullscreen mode Exit fullscreen mode

When you're debugging an API response, the difference between
those two is the difference between finding the problem in
30 seconds or 10 minutes.

Always format JSON when you're reading it. Always minify it
when you're sending it in production.

The most common JSON mistakes

Trailing commas

This is the number one JSON error. It's valid in JavaScript
but illegal in JSON:

{
  "name": "DevCrate",
  "tools": 12,
}
Enter fullscreen mode Exit fullscreen mode

Remove the comma after the last item. Every time.

Single quotes instead of double quotes

JSON requires double quotes. Single quotes are not valid —
even though JavaScript accepts them just fine. This breaks:

{
  'name': 'DevCrate'
}
Enter fullscreen mode Exit fullscreen mode

This works:

{
  "name": "DevCrate"
}
Enter fullscreen mode Exit fullscreen mode

Unquoted keys

Keys must always be strings in double quotes. This is valid
JavaScript but invalid JSON:

{
  name: "DevCrate"
}
Enter fullscreen mode Exit fullscreen mode

Comments

JSON has no comment syntax. This will throw an error:

{
  // This is the app name
  "name": "DevCrate"
}
Enter fullscreen mode Exit fullscreen mode

If you need comments in a config file, consider YAML instead —
it supports comments and is generally more human-friendly for
configuration.

Mismatched brackets

Every { needs a }. Every [ needs a ]. In deeply nested
JSON this is easy to lose track of. A formatter catches this
immediately.

Validating JSON

Validation is just asking one question — is this valid JSON
that any parser can read? The answer is binary: yes or no.

When you paste JSON into a validator, it will either confirm
the structure is correct or point you to the exact line where
something is wrong. This is dramatically faster than reading
through the JSON manually trying to spot the issue.

Common reasons JSON fails validation:

  • Trailing commas
  • Single quotes
  • Missing quotes around keys
  • Unescaped special characters in strings
  • Missing closing brackets or braces

Converting JSON to other formats

Sometimes JSON isn't the right format for the job. A few
common conversions:

JSON to YAML — YAML is more readable and supports comments,
making it popular for configuration files. Many DevOps tools
prefer YAML over JSON.

JSON to CSV — useful when your JSON contains a flat array
of objects and you want to open the data in a spreadsheet.
Works best with consistent, non-nested structures.

JSON to object keys — sometimes you just need a list of
all the keys in a JSON object to understand its structure
without reading through all the values.

A practical example

Here's a real workflow. You're debugging an API call and the
response comes back as a wall of minified JSON:

{"user":{"id":"abc123","name":"William","email":"william@example.com","created_at":"2026-01-15T10:30:00Z","preferences":{"theme":"dark","notifications":true,"timezone":"America/New_York"}}}
Enter fullscreen mode Exit fullscreen mode

Paste it into the DevCrate JSON Transformer,
hit Format, and you get:

{
  "user": {
    "id": "abc123",
    "name": "William",
    "email": "william@example.com",
    "created_at": "2026-01-15T10:30:00Z",
    "preferences": {
      "theme": "dark",
      "notifications": true,
      "timezone": "America/New_York"
    }
  }
}
Enter fullscreen mode Exit fullscreen mode

Now you can actually read it. The bug that was invisible in the
minified version becomes obvious in seconds.

Everything runs in your browser. Your API responses, your
internal payloads, your data — none of it touches a server.

The one rule

If you take nothing else from this guide, take this: always
format your JSON before you read it. It costs two seconds and
saves ten minutes. Every time.


I'm William, the developer behind DevCrate. I built the JSON
Transformer because too many formatters send your data to a
server. Yours stays in your browser — always. I'm building
DevCrate from home one tool at a time. My oldest son is
graduating in May and moving on to Officer Candidate School —
couldn't be more proud. My youngest is heading into his undergrad
and every subscriber helps make that a little easier. If this
guide helped you, try the tool — it's free, runs entirely in
your browser, and your data never leaves your machine. And if
there's something missing or something that could work better,
the contact form on the about page comes straight to me.

I'm always listening.

Top comments (0)