{jsonbody.com}

What Is JSON? Syntax Rules, Data Types & Examples

A beginner-friendly guide to JSON: where it is used, the syntax rules that make it valid, its six data types, and when to use objects or arrays.

Loading…

By jsonbody.com Team ·

JSON (JavaScript Object Notation) is a plain-text format for structured data. It is the most common way for web APIs, mobile apps and configuration files to exchange data, because it is easy for people to read and for every programming language to parse.

Here is a small JSON document describing a user:

{
  "id": 101,
  "name": "Asha Rao",
  "active": true,
  "roles": ["admin", "editor"],
  "address": { "city": "Pune", "zip": "411001" },
  "manager": null
}

Paste it into the JSON Parser to format it, check it and explore it as a tree.

Where JSON is used

  • APIs: most REST and GraphQL APIs send and receive JSON.
  • Configuration: package.json, tsconfig.json, VS Code settings and many cloud tools.
  • Storage: document databases such as MongoDB, and JSON columns in PostgreSQL and MySQL.
  • Logs and events: structured logs, webhooks and message queues.

JSON syntax rules

JSON is strict. A document is valid only if it follows these rules:

  1. Data is written as name/value pairs: "name": "Asha".
  2. Keys must be strings in double quotes. {name: "Asha"} is invalid.
  3. Strings use double quotes only, never single quotes.
  4. Pairs and array items are separated by commas, with no comma after the last item.
  5. Objects use curly braces { } and arrays use square brackets [ ].
  6. No comments are allowed.
  7. Special characters in strings are escaped with a backslash, such as \" and \n.

Breaking any rule makes the whole document invalid. The JSON Validator and the JSON Parser show exactly where the problem is, and Common JSON errors explains how to fix each one.

JSON data types

JSON has six data types:

TypeExampleNotes
String"Pune"Text in double quotes
Number42, -3.5, 1.2e6No leading zeros, no NaN or Infinity
Booleantrue, falseLowercase only
NullnullAn intentionally empty value
Object{"city": "Pune"}Unordered name/value pairs
Array[1, 2, 3]An ordered list of values

There is no date type: dates are usually strings in ISO 8601 format, such as "2026-11-26T10:30:00Z". There is no undefined either; leave the key out or use null.

Objects vs arrays

Use an object when each value has a name, like the fields of one record:

{ "id": 1, "title": "Keyboard", "price": 49.99 }

Use an array when you have a list of similar items, where order matters:

[
  { "id": 1, "title": "Keyboard" },
  { "id": 2, "title": "Mouse" }
]

Objects and arrays nest inside each other to any depth. A typical API response is an object that contains an array of objects. To explore deep nesting, open the JSON in the JSON Viewer or the Tree View of the JSON Parser.

JSON compared with other formats

JSON is more compact than XML and stricter than YAML. See JSON vs YAML vs XML for a side-by-side comparison, and convert between them with JSON to YAML or JSON to XML.

Next steps

More from the blog