Skip to content
Filebird

JSON for beginners: syntax, errors and formatting

By the Filebird team · Updated October 18, 2026 · 7 min read

JSON shows up everywhere: web APIs, configuration files, exports from apps, data you copy from a browser's developer tools. It looks like a wall of brackets until you know what you are looking at. Once you do, it becomes one of the easiest data formats to read, and the errors it produces turn out to be repetitive and easy to fix.

This guide explains the structure, the syntax rules that matter, the mistakes that cause most error messages, and how to format, minify and validate JSON in practice.

What JSON is for

JSON stands for JavaScript Object Notation. It is plain text that describes data in a way both people and programs can read. It began in the JavaScript world but is now used by nearly every programming language, which is why it is the common language for sending data between a website and a server, or for storing settings.

Because it is plain text, you can open a JSON file in any editor. The trouble is only that machines often write it with no spacing at all, so a few thousand values arrive on one line. That is where a formatter helps.

The building blocks

JSON has only a few kinds of values:

  • Objects, written in curly braces, hold named values: {"name": "Sara", "age": 31}. Each name is called a key and is always in double quotes.
  • Arrays, written in square brackets, hold an ordered list: ["red", "green", "blue"].
  • Strings, always in double quotes: "hello".
  • Numbers, written plainly: 42, -3.5, 1e6.
  • Booleans: true and false, lowercase and without quotes.
  • Null: null, meaning "no value".

You nest them freely. An object can contain an array of objects, and so on:

{
  "user": "sara",
  "active": true,
  "orders": [
    {"id": 1, "total": 19.99},
    {"id": 2, "total": 5}
  ],
  "notes": null
}

To read it, start at the outside. This is an object with four keys. The value of orders is an array holding two objects. That reading habit, outside to inside, works for any JSON document, however large.

The syntax rules that matter

JSON is strict. A person would understand a slightly sloppy version, but a parser will refuse it. Remember these rules:

  1. Keys and strings use double quotes only. Single quotes are not valid.
  2. Items are separated by commas, and there is no comma after the last item.
  3. Every opening brace or bracket needs a matching closing one.
  4. Keys are followed by a colon, and key-value pairs are separated by commas.
  5. There are no comments. Neither // nor /* */ are allowed in standard JSON.
  6. Values must be one of the types above. Things like undefined, NaN or a date such as new Date() are not JSON.

Special characters inside a string need escaping with a backslash: \" for a quote, \\ for a backslash, \n for a new line. A real line break inside a string is invalid.

The mistakes behind most errors

When people paste JSON into a validator and get an error, it is nearly always one of these:

  • A trailing comma: {"a": 1, "b": 2,} fails because of the comma after the last pair. This is the most common problem, particularly when you delete the last line of a list and forget the comma on the line above it.
  • Single quotes: {'name': 'Sara'} looks fine and is not valid. It happens when someone copies a Python dictionary, which allows single quotes.
  • Unquoted keys: {name: "Sara"} is valid JavaScript but not valid JSON.
  • Missing comma between items: Two values that run into each other with nothing between them.
  • Comments left in: Config files edited by hand often have notes that the parser rejects.
  • Smart quotes: Text copied from a word processor or chat app may contain curly quotes (“ ”) that look right but are different characters from the straight quote ".
  • Truncated data: A copy that stopped part-way, so a closing bracket is missing at the end.
  • Python or JavaScript literals: True, None or undefined instead of true and null.

The common thread is that the error appears where the parser gave up, which can be just after the real mistake. If the message says there is a problem at line 12, look at line 12 and the line before it.

Formatting versus minifying

These are two views of the same data. They hold identical information, and a program reads them the same way.

Formatting (or pretty-printing) adds line breaks and indentation so the structure is visible. Use it when you need to read, review or edit the data, or when you commit a config file that people will maintain.

Minifying removes every unnecessary space and line break. The result is smaller, which matters when data is sent over a network or embedded in a page, and it fits on one line when you must paste it into a field that does not allow breaks. The savings come from whitespace alone, so the amount depends on how much indentation the original had.

The JSON formatter does both. Paste or open your data and choose pretty-print to read it, or minify to compact it. If you need keys in a predictable order, for instance to compare two files, sorting keys makes the layout consistent. Sorting changes the order of keys inside objects but not the order of array items, and it does not change the meaning of the data.

Validating and finding the error

Validation checks whether the text is legal JSON. A good validator reports the position of the problem as a line and column, which is far more useful than a general failure message. In the formatter, an invalid input shows an error with its location, so you can jump straight to it, fix it and try again.

A workable routine when your JSON will not parse:

  1. Paste it into the formatter and read the error message and position.
  2. Look for the usual suspects at that line: a trailing comma, a missing comma, quotes.
  3. Fix one error at a time and re-run, because one mistake can hide others.
  4. If the file is huge, check the very beginning and very end first. Many failures are a missing final bracket or extra text before the first brace.

Valid JSON is not the same as correct data. A validator confirms the syntax. It cannot tell you that "age": "thirty" should have been a number. That check belongs to the program that uses the data.

JSON compared with other formats

JSON is not the only format, and knowing the differences stops you from using the wrong one. CSV is better for flat tables with rows and columns, but cannot show nesting. XML is more verbose and supports attributes, and is still common in older systems. YAML is easier to read and write by hand and allows comments, which is why many configuration files use it, but its indentation rules cause their own errors. JSON sits in the middle: strict, compact, and universally supported.

Try it: paste some JSON into the JSON formatter and see how its structure appears as soon as it is indented.

Frequently asked questions

Can JSON contain comments?

No. Standard JSON has no comment syntax, and a parser will reject it. If you need notes, add a regular key such as "_comment" and ignore it in your program, or use a format like YAML for hand-edited configuration.

Why does my JSON fail when it looks correct?

Usually because of a trailing comma, single quotes or invisible characters such as curly quotes copied from a document. The error position from a validator points you to the line to inspect.

Does minifying change my data?

No. It only removes whitespace outside of strings, so a program reads the minified and formatted versions as the same data. Spaces inside string values are preserved.

What is the difference between null and an empty string?

null means there is no value, and "" is a real value that happens to be empty. Programs treat them differently, so use null when something is unknown or absent.

Tools mentioned in this guide

Keep reading

Browse all guides