Ctrl + K
JSON11 min read

JSON Syntax Explained

Master JSON syntax by learning its rules, structure, supported data types and common validation errors.

Published: 2026-07-08

One of the biggest advantages of JSON is its simplicity. Unlike many older data formats, JSON uses only a small number of syntax rules, making it easy for both humans and machines to read. However, JSON is also extremely strict. A single missing comma, incorrect quotation mark or trailing comma is enough to make an entire document invalid.

Understanding JSON syntax is essential for anyone working with APIs, configuration files, web applications or cloud services. Once you know the basic rules, you'll be able to read and write JSON confidently in virtually every programming language.

What Is JSON Syntax?

JSON syntax is the set of rules that defines how JSON documents must be written. Every parser follows these rules exactly. If any rule is broken, the parser throws an error instead of trying to guess what the document should mean.

💡 Unlike JavaScript, JSON never allows comments, trailing commas or unquoted property names.

A Complete JSON Example

The following document demonstrates valid JSON syntax containing most supported value types.

{
  "id": 15,
  "name": "Alice",
  "age": 28,
  "isAdmin": false,
  "skills": [
    "JavaScript",
    "TypeScript",
    "React"
  ],
  "address": {
    "city": "London",
    "country": "United Kingdom"
  },
  "manager": null
}

This document is valid because every property name uses double quotes, values are separated correctly and no extra commas appear after the final property.

The Basic JSON Rules

Every valid JSON document follows the same small collection of syntax rules.

  • Objects use curly braces {}.
  • Arrays use square brackets [].
  • Property names must use double quotes.
  • Keys and values are separated with a colon.
  • Properties are separated with commas.
  • Trailing commas are not allowed.
  • Comments are not supported.

Objects

Objects represent collections of named properties. Every property consists of a key followed by its corresponding value.

{
  "framework": "Next.js",
  "version": 16
}

Objects are ideal for representing users, products, configuration settings and other structured entities.

Arrays

Arrays contain ordered collections of values. Every item is separated by a comma and may itself be another object or array.

[
  "HTML",
  "CSS",
  "JavaScript"
]

Arrays frequently appear in API responses when multiple resources need to be returned together.

Supported JSON Data Types

JSON intentionally supports only a small number of value types. This limited set keeps parsers simple while covering nearly every practical use case.

TypeExample
String"Hello"
Number42
Booleantrue / false
Nullnull
Object{}
Array[]

Unlike JavaScript, JSON does not support functions, dates, undefined values, symbols or regular expressions.

Strings

Strings are always enclosed in double quotation marks. Single quotes are never valid in JSON.

"username": "alice"
⚠️ Using single quotes is one of the most common reasons a JSON document fails validation.

Numbers

Numbers can be integers or floating-point values. They are written without quotation marks.

{
  "count": 15,
  "price": 19.95
}

Because numbers are stored as actual numeric values, they can be processed directly without additional conversion.

Booleans

Boolean values represent true or false. They are commonly used for flags, permissions and feature switches.

{
  "published": true,
  "archived": false
}

Null Values

The null value represents the intentional absence of data. It differs from an empty string or the number zero.

{
  "middleName": null
}

Nested Objects and Arrays

JSON structures can contain other objects and arrays, allowing developers to model complex relationships while keeping the data organized.

{
  "user": {
    "name": "Alice",
    "roles": [
      "Admin",
      "Editor"
    ]
  }
}

Although nesting is powerful, excessively deep structures can become difficult to read and maintain. Whenever possible, keep nesting to a reasonable depth.

Common JSON Syntax Errors

Most JSON validation errors fall into a small number of categories. Learning to recognize them will save a significant amount of debugging time.

InvalidReason
{ name: "John" }Property names must use double quotes.
{ "age":, 20 }Missing value after colon.
{ "a":1, }Trailing comma is not allowed.
'text'Strings must use double quotes.
// commentComments are not part of the JSON specification.
⚠️ Unlike many programming languages, JSON parsers never ignore syntax errors. Even a single invalid character prevents the entire document from being parsed.

Formatting JSON

Although whitespace is generally ignored by JSON parsers, properly formatted JSON is much easier for humans to read. Indentation makes nested objects, arrays and long documents significantly easier to understand.

A JSON formatter automatically indents your document, aligns nested structures and highlights syntax errors, making debugging much faster.

Escaping Characters

Certain characters inside JSON strings must be escaped to remain valid. This is especially important when storing paths, quotation marks or multi-line text.

{
  "message": "She said: \"Hello\"",
  "path": "C:\\Users\\John"
}

Validating JSON

Before sending JSON to an API or saving it to a file, it's a good idea to validate it. A validator checks whether the document follows the JSON specification and reports the exact location of syntax errors.

💡 Validate JSON before committing configuration files or deploying applications. Finding syntax mistakes early prevents difficult runtime errors later.

Best Practices

  • Always use double quotes for property names and strings.
  • Choose descriptive property names.
  • Avoid unnecessary nesting.
  • Keep formatting consistent across projects.
  • Validate JSON before using it.
  • Escape special characters correctly.
  • Use UTF-8 encoding whenever possible.

Frequently Asked Questions

Can JSON contain comments?

No. The official JSON specification does not support comments. Some tools allow them, but standard JSON parsers reject them.

Why must property names use double quotes?

Double quotes are required by the JSON specification. Omitting them or using single quotes results in invalid JSON.

Can arrays contain different data types?

Yes. Arrays may contain strings, numbers, objects, arrays, booleans and null values together.

Does whitespace affect JSON?

No. Spaces, tabs and line breaks outside strings are ignored by parsers and exist only to improve readability.

How can I quickly check whether my JSON is valid?

Use a JSON Validator. It will identify syntax errors and point to the exact location where parsing failed.

Conclusion

JSON syntax is intentionally simple, but it is also very strict. Learning the basic rules for objects, arrays, strings, numbers and nesting allows you to create reliable JSON documents for APIs, configuration files and web applications. By combining proper formatting with validation tools, you can avoid the majority of common JSON errors and work more efficiently with structured data.