JSON Syntax Explained

JSON Syntax Explained: A Complete Beginner’s Guide

If you’ve ever opened an API response, a config file, or a .json file and felt like you were looking at a wall of brackets and quotes, this guide is for you. JSON syntax is actually one of the simplest data formats to learn — it has a small, fixed set of rules, and once they click, you’ll be able to read and write JSON confidently without needing to look anything up.

We’ll walk through every part of JSON syntax with real examples, and by the end you’ll understand not just what the rules are, but why they exist the way they do.

What Is JSON?

JSON stands for JavaScript Object Notation. Despite the name, it’s not tied to JavaScript specifically — it’s a language-independent data format, which is exactly why it became the standard way applications exchange data over the web. Python, Java, PHP, C#, Ruby, and virtually every other programming language can read and write JSON natively or with a built-in library.

At its core, JSON represents data as a combination of just two structures:

  • Objects — collections of key-value pairs, wrapped in curly braces { }
  • Arrays — ordered lists of values, wrapped in square brackets [ ]

Everything in JSON is built from those two building blocks, combined with a small set of value types.

The Building Blocks: JSON Value Types

Every value in JSON falls into one of six types:

  1. String — text, always wrapped in double quotes: "hello"
  2. Number — integers or decimals, no quotes: 42, 3.14, -7
  3. Booleantrue or false, lowercase, no quotes
  4. Null — represents “no value,” written as null, lowercase, no quotes
  5. Object — a set of key-value pairs: {"key": "value"}
  6. Array — an ordered list of values: [1, 2, 3]

That’s the entire type system. Unlike programming languages, JSON has no separate integer vs. float type, no date type, no undefined — just those six.

json syntax

JSON Objects: Key-Value Pairs

An object is written with curly braces, and inside it, keys and values are separated by a colon, with pairs separated by commas:

{
  "name": "Kings Tools",
  "type": "utility",
  "isFree": true
}

A few strict rules apply here that trip up almost everyone at some point:

Keys must always be double-quoted strings. This is one of the most common sources of invalid JSON:

{name: "Kings Tools"}

That’s invalid — name needs to be "name". JavaScript object literals allow unquoted keys, but JSON does not. This is a frequent source of confusion because JSON and JavaScript object syntax look almost identical but aren’t governed by the same rules.

Only double quotes are valid — not single quotes. {'name': 'value'} is invalid JSON, even though it’s perfectly valid JavaScript.

JSON Arrays: Ordered Lists

Arrays hold a list of values inside square brackets, separated by commas:

["red", "green", "blue"]

Arrays can hold any JSON value type, including mixed types:

["text", 42, true, null, {"nested": "object"}]

And arrays can be nested inside objects, and objects nested inside arrays — this is how JSON represents complex, real-world data:

{
  "users": [
    { "name": "Alex", "active": true },
    { "name": "Sam", "active": false }
  ]
}

Strings in JSON

Strings follow a specific set of escaping rules. If a string needs to include a double quote, backslash, or certain control characters, they must be escaped with a backslash:

CharacterEscaped as
Double quote\"
Backslash\\
Newline\n
Tab\t
Carriage return\r

For example, a string containing a quote looks like this:

{"message": "She said \"hello\" to me"}

Forgetting to escape an internal double quote is a common way JSON breaks — the parser sees the unescaped quote as the end of the string, and everything after it becomes a syntax error.

Numbers in JSON

JSON numbers don’t use quotes, and they follow a few specific rules:

  • No leading zeros: 007 is invalid, 7 is correct
  • No + sign for positive numbers: +5 is invalid
  • Decimals need a digit before the decimal point: .5 is invalid, 0.5 is correct
  • Scientific notation is supported: 1.5e10 is valid

There’s also no distinction between integers and floating-point numbers at the syntax level — 5 and 5.0 are both just “numbers.” How they’re interpreted (as an int or a float) is up to whatever programming language parses the JSON, not JSON itself.

The Rules That Trip Everyone Up

If we had to narrow down JSON syntax to the handful of rules that cause the most errors, it would be these:

No trailing commas. This is, by a wide margin, the single most common JSON syntax error:

{
  "a": 1,
  "b": 2,
}

That trailing comma after 2 makes this invalid. It’s easy to leave behind when you’re editing JSON by hand and remove the last item, or when you’re used to languages that tolerate trailing commas.

No comments. Standard JSON has no concept of // or /* */ comments at all, unlike JSON5 or JSONC (a JSON variant VS Code uses for config files). If you paste a JSON file with comments into a strict validator, it will fail.

No unquoted keys. Covered above, but worth repeating since it’s so common when JSON is hand-written by someone used to JavaScript.

Matching brackets. Every { needs a }, every [ needs a ]. In deeply nested JSON, it’s easy to lose track of one — this is where a validator that points to the exact line becomes genuinely useful rather than just scanning visually.

A Complete Valid Example

Here’s a slightly larger, fully valid JSON document that uses everything covered above:

{
  "product": "JSON Formatter",
  "version": 2,
  "price": 0,
  "isFree": true,
  "discontinued": null,
  "tags": ["developer-tools", "utilities", "free"],
  "maintainer": {
    "team": "Kings Tools",
    "contact": "support@kingstools.online"
  }
}

Notice every key is double-quoted, every string uses double quotes, there’s no trailing comma anywhere, and the nested object (maintainer) and array (tags) both follow the same rules as the outer object.

Whitespace in JSON

One thing that surprises beginners: whitespace (spaces, tabs, line breaks) between tokens is completely optional in JSON and has no effect on meaning. These two examples represent identical data:

{"name":"Kings Tools","free":true}
{
  "name": "Kings Tools",
  "free": true
}

The first is minified — smaller in file size, harder for a human to read. The second is beautified — larger, but far easier to scan. This is exactly the distinction our tool’s Beautify and Minify modes handle: the underlying data never changes, only its formatting.

Is JSON Case-Sensitive?

Yes, in two important ways. First, true, false, and null must be lowercase — True, FALSE, or Null are all invalid JSON, even though some programming languages (like Python) capitalize their equivalents. Second, JSON keys are case-sensitive as data — "Name" and "name" are treated as two completely different keys, not the same key with different capitalization. This matters when comparing JSON from different sources, since a mismatched key case looks identical to a human eye but behaves as an entirely separate field to any code reading it.

JSON vs. JavaScript Object Literals

Because JSON’s syntax was derived from JavaScript object literals, the two are often confused — but they’re not interchangeable. A JavaScript object literal can have unquoted keys, single-quoted strings, trailing commas, comments, and even functions as values. None of that is valid in strict JSON. If you’ve ever copied what looked like “JSON” out of JavaScript source code and had it fail validation, this is almost always why — it was actually a JavaScript object literal, which is a related but distinct syntax.

Checking Your Own JSON

Understanding the rules is one thing — actually catching a syntax mistake in a long, real-world JSON payload by eye is another. That’s exactly the gap our JSON Formatter and Validator is built to close: paste your JSON in, and if something’s wrong, it tells you the specific line and column, rather than making you scan the whole document manually. It also beautifies valid JSON into clean, readable formatting, which makes spotting structural issues in nested data much easier in the first place.

Summary

JSON syntax comes down to a short list of rules: double-quoted keys, double-quoted strings, no trailing commas, no comments, and everything built from objects and arrays. Once those rules are second nature, JSON becomes one of the easiest data formats to read, write, and debug — which is exactly why it’s the default choice for APIs, configuration files, and data exchange across virtually every modern programming language.

Leave a Reply

Your email address will not be published. Required fields are marked *