FormatterHQ

Data formats

What Is JSON? Syntax, Data Types & Rules Explained

A plain-English guide to JSON — the four primitive types plus objects and arrays, the strict syntax rules, and the gotchas behind most parse errors.

Published 5 min read

JSON (JavaScript Object Notation) is the most common way to move structured data between programs. APIs return it, config files use it, databases store it, and almost every language can read and write it. This guide explains exactly what JSON is: the handful of value types it supports, how objects and arrays nest, and the strict syntax rules that cause most of the errors beginners hit.

Want to see it in action while you read? Paste any JSON into the JSON formatter to pretty-print it, or the JSON validator to check it for errors.

What JSON actually is

JSON is a text format for representing data as a combination of a few simple building blocks. It was derived from JavaScript object syntax, but it is language-independent — the format is defined by RFC 8259 and the ECMA-404 standard, and parsers exist for every mainstream language. A JSON document is just a string; your program parses that string into native data structures (objects, arrays, numbers) and serialises them back to a string to send or store.

The six JSON value types

Every value in JSON is one of exactly six types — four primitives and two structures:

TypeExampleNotes
String"hello"Always double quotes. Use \", \\, \n etc. to escape.
Number42, -3.14, 2.5e8One numeric type — no separate int/float, no NaN or Infinity.
Booleantrue, falseLowercase only.
NullnullLowercase only — represents "no value".
Object{"id": 1}An unordered set of "key": value pairs.
Array[1, 2, 3]An ordered list of values of any type.

Notice what is missing: there is no date type, no comment syntax, and no way to reference another part of the document. Dates are usually written as strings (ISO 8601, e.g. "2026-11-20T09:00:00Z"), and the receiving code is responsible for parsing them.

Objects

An object is wrapped in curly braces and holds "key": value pairs separated by commas. Keys are always strings in double quotes; values can be any of the six types, including more objects and arrays:

{
  "id": 42,
  "name": "Ada Lovelace",
  "active": true,
  "roles": ["admin", "author"],
  "profile": {
    "city": "London",
    "joined": "2026-01-15"
  },
  "deletedAt": null
}

Objects are unordered — {"a":1,"b":2} and {"b":2,"a":1} are equivalent — and keys should be unique. To explore a large object visually, open it in the JSON tree viewer, which collapses and expands nested nodes.

Arrays

An array is wrapped in square brackets and holds an ordered list of values. Unlike objects, order matters and there are no keys:

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

[
  {"sku": "A1", "qty": 2},
  {"sku": "B7", "qty": 1}
]

JSON allows arrays of mixed types ([1, "two", true, null]), but most APIs keep arrays homogeneous — a list of objects with the same shape — because that maps cleanly onto tables and typed models.

The syntax rules that cause most errors

JSON is deliberately strict. Five rules account for the vast majority of "invalid JSON" errors:

  • Double quotes only. 'single' quotes are invalid, and keys must be quoted — {name: "x"} is a JavaScript object literal, not JSON.
  • No trailing commas. [1, 2, 3,] and {"a": 1,} are both errors.
  • No comments. // like this or /* this */ will fail. (If you need comments, see JSON5/JSONC below.)
  • Lowercase keywords. True, FALSE and NULL are invalid — they must be true, false, null.
  • No leading zeros or hex. 007 and 0xFF are not valid numbers.

When a parser rejects your data, paste it into the validator — it reports the exact line and column of the first error. If the document is broken by a stray comma or quote, the JSON fixer can often repair it automatically. For a deeper walkthrough of specific error messages, see our guide on how to debug invalid JSON.

Escaping characters inside strings

Because strings are delimited by double quotes, any double quote inside a string must be escaped with a backslash, along with a few other characters. The escape sequences are:

  • \" — a double quote
  • \\ — a backslash
  • \/ — a forward slash (optional, but allowed)
  • \n, \t, \r — newline, tab, carriage return
  • \uXXXX — any Unicode character by its four-digit hex code point

So a Windows path and a quoted phrase look like this: {"path": "C:\\Users\\ada", "quote": "she said \"hi\""}. Forgetting to escape a backslash in a path is a classic source of “invalid JSON” errors. If you are embedding a chunk of JSON inside another JSON string, the JSON escape tool does the nested escaping for you.

Numbers, precision and big integers

JSON has a single number type and does not distinguish integers from floats. Two things to watch: JSON cannot represent NaN or Infinity (serialisers usually emit null or throw), and very large integers can lose precision because many parsers read numbers as 64-bit floats. If you need exact large IDs (for example a 19-digit database key or a blockchain value), send them as strings rather than numbers so no digits are rounded away.

How JSON is used

  • APIs send and receive JSON request/response bodies (with the application/json content type).
  • Config files such as package.json and tsconfig.json are JSON.
  • Databases — document stores like MongoDB, and JSON columns in PostgreSQL/MySQL — store JSON directly.
  • Logs and messaging often use JSON (or newline-delimited JSON) so each record is machine-readable.

JSON vs other formats

JSON is not the only option. YAML and TOML are common for human-edited config because they allow comments and are less punctuation-heavy; XML is still used in older enterprise systems. We compare the trade-offs in JSON vs YAML vs TOML. If you need JSON with comments and trailing commas for your own config files, JSON5 is a superset that adds exactly that — strict JSON stays the right choice for data on the wire.

Reading and editing JSON by hand

Minified JSON arrives as one long line, which is unreadable. Run it through the formatter to indent it, or edit it safely in the JSON editor, which highlights syntax and flags mistakes as you type. Everything runs in your browser, so the data never leaves your device.

Key takeaways

  • JSON values are one of six types: string, number, boolean, null, object, array.
  • Objects are unordered key/value maps; arrays are ordered lists.
  • Use double quotes, no trailing commas, no comments, and lowercase true/false/null.
  • There is no date type — dates are strings your code parses.
  • When in doubt, validate and format before you ship.
  • JSON
  • Data formats
  • Beginner
  • Syntax

Frequently asked questions

What are the data types in JSON?
JSON has six value types: string, number, boolean (true/false), null, object (key/value pairs) and array (an ordered list). There is no separate integer or float type and no date type — dates are written as strings.
Can JSON have comments?
No. Standard JSON does not allow // or /* */ comments, and a parser will reject them. If you need comments in a config file, use JSON5 or JSONC, which are supersets of JSON.
Why does my JSON say “unexpected token”?
Almost always a syntax rule: single quotes instead of double, a trailing comma, an unquoted key, or a capitalised True/Null. Paste it into the JSON validator to see the exact line and column, or the JSON fixer to repair it.
Are JSON object keys ordered?
No. Objects are unordered sets of key/value pairs, so {"a":1,"b":2} equals {"b":2,"a":1}. Arrays, by contrast, are ordered — position matters.
Is JSON the same as a JavaScript object?
No. JSON is a text format with stricter rules: keys must be double-quoted strings and only the six JSON types are allowed. A JavaScript object literal can have unquoted keys, functions, comments and undefined, none of which are valid JSON.

Tools used in this guide