Web Analytics
Skip to content
← All writing
Engineeringen · OriginalAugust 24, 2026 · 7 min read

JSON Data Types Explained: Strings, Numbers, Objects, Arrays & More

A clear guide to JSON's six data types, string, number, object, array, boolean and null, with examples of nested objects and arrays.

M
Mezi Aris ApronnyFounder, Nelenga · Seginim, Bengkulu Selatan
JSON Data Types Explained: Strings, Numbers, Objects, Arrays & More

JSON has exactly six data types: string, number, object, array, boolean, and null. Everything you ever put in a JSON file is one of those six, or some combination of them nested inside each other. That is the whole vocabulary, and once you know how each type behaves you can read or write any JSON document with confidence.

This guide walks through all six with real examples, including how JSON strings must be quoted, how numbers are restricted, and how objects and arrays nest to build anything from a config file to an API response. If you are still fuzzy on the format itself, start with what is JSON and come back.

The six JSON data types at a glance

Here is the full set, with a minimal example of each:

{
  "name": "Ada",
  "age": 36,
  "active": true,
  "nickname": null,
  "skills": ["json", "python"],
  "address": { "city": "London" }
}

That single object uses every type:

  • String: "Ada" and "London", text in double quotes.
  • Number: 36, any integer or decimal.
  • Boolean: true, either true or false.
  • Null: null, an explicit “no value”.
  • Array: ["json", "python"], an ordered list.
  • Object: { "city": "London" }, a set of key/value pairs.

Three of these are scalar (string, number, boolean) plus the null literal, and two are containers (object and array) that hold the others. The containers are what let JSON describe complex data. Everything else is a leaf.

JSON strings (and why they must use double quotes)

A JSON string is text wrapped in double quotes: "hello". Single quotes are not allowed. 'hello' is invalid JSON and any parser will reject it, which is one of the most common errors people hit when they hand-write JSON or copy it from JavaScript.

Inside a string you can include Unicode characters directly, and you escape special ones with a backslash. The reserved escapes are \" for a quote, \\ for a backslash, \n for newline, \t for tab, plus \uXXXX for any character by its code point. So a Windows path becomes "C:\\Users\\Ada", doubling each backslash.

{
  "quote": "She said \"hi\"",
  "path": "C:\\logs\\app.txt",
  "emoji": "\u2764"
}

Get the escaping wrong and the parse fails on the whole document, not just that line. If you keep tripping over backslashes and quotes, the rules are worth a proper read in JSON escape characters explained. Keys in an object are strings too, so they follow the same double-quote rule.

JSON numbers (integers, floats, no NaN or Infinity)

A JSON number is written plain, with no quotes: 36, -4, 3.14, 2.5e8. There is a single number type, so JSON does not distinguish integers from floats the way many languages do. 10 and 10.0 are both just numbers.

The grammar allows an optional minus sign, a decimal fraction, and an exponent (e or E). What it does not allow trips people up:

  • No leading zeros: 007 is invalid, write 7.
  • No leading plus sign: +7 is invalid.
  • No NaN, Infinity, or -Infinity. JSON has no way to write them.
  • A hanging decimal like 5. or .5 is invalid, use 5.0 and 0.5.

Because there is no Infinity or NaN, code that serializes those values has to decide what to do. Most libraries throw an error or emit null instead. Large integers are another quiet trap: values beyond roughly 9 quadrillion can lose precision when a parser reads them as a 64-bit float, so IDs like 12345678901234567890 are safest stored as strings.

The JSON object: key/value pairs explained

A JSON object is an unordered set of key/value pairs wrapped in curly braces. Each key is a string, followed by a colon, followed by any JSON value. Pairs are separated by commas.

{
  "id": 42,
  "title": "Getting started",
  "published": true,
  "tags": ["intro", "json"]
}

Three rules save you from most object bugs. Keys must be double-quoted strings, even simple ones like id. There is no trailing comma allowed after the last pair, so {"a": 1,} is invalid. And while the spec technically allows duplicate keys, you should never write them: parsers usually keep the last one and silently drop the rest, which hides data.

Objects have no guaranteed order. If order matters to you, that is a signal you actually want an array. Learn objects well and you understand most JSON you will meet, since API responses and config files are objects at the top level. For the exact punctuation rules across the whole format, see JSON syntax rules.

The JSON array: ordered lists of values

A JSON array is an ordered list of values wrapped in square brackets, separated by commas: [1, 2, 3]. Unlike an object, order is meaningful, and you access items by position rather than by key.

Arrays can hold any JSON type, and the values do not have to be the same type, though keeping them consistent makes life easier for whoever parses the data:

["json", 42, true, null, {"nested": "ok"}]

The same rules apply: no trailing comma after the last item, so [1, 2,] is invalid. An empty array is just [], which is valid and useful. A common shape in real APIs is an array of objects, one object per record, which is how you would represent a list of users or blog posts.

Nesting objects and arrays inside each other

This is where JSON gets its expressive power. Any value inside an object or array can itself be an object or an array, to any depth. That lets you model JSON nested objects and arrays that mirror real-world structure.

{
  "user": {
    "name": "Ada",
    "roles": ["admin", "editor"],
    "contacts": [
      { "type": "email", "value": "ada@example.com" },
      { "type": "phone", "value": "555-0100" }
    ]
  }
}

Reading it is a matter of following the brackets: user is an object, roles is an array of strings, and contacts is an array of objects. There is no depth limit in the spec, but deeply nested data gets hard to read and harder to debug. When a document goes several levels deep, indentation is the only thing keeping it legible, which is exactly what a formatter is for.

Booleans and null: the two literal values

JSON has three literal keywords, and they are always lowercase: true, false, and null. A boolean is true or false with no quotes. Put quotes around it and you get the string "true", which is a different value that many bugs are made of.

{
  "active": true,
  "verified": false,
  "deletedAt": null
}

null means an explicit, intentional absence of value. It is not the same as 0, not the same as an empty string "", and not the same as the key being missing entirely. Those four states can each mean something different in an API, so choose deliberately. deletedAt: null says “this was never deleted”, while omitting the key might mean “we did not check”. Case matters here too: True, FALSE, and NULL are all invalid JSON, since the format borrows JavaScript’s lowercase spelling.

What JSON deliberately leaves out (dates, comments, undefined)

JSON is intentionally small, so several things you might expect are simply not part of it. There is no date type. A timestamp is stored as a string, almost always in ISO 8601 form like "2026-08-17T09:00:00Z", and your code parses it back into a date on the way in.

There are no comments in standard JSON. // and /* */ will both cause a parse error, which surprises people coming from JavaScript config files. If you need annotations, either use a superset like JSON5 for local config, or add a real key such as "_comment": "..." that your program ignores. There is also no undefined: that is a JavaScript concept, and JSON.stringify drops any property whose value is undefined rather than writing it out. Trailing commas, single quotes, and functions are all out too, for the same reason. The small type set is the point, since it is what makes JSON portable across every language.

Try it with the formatter

The fastest way to make sense of a messy or deeply nested JSON document is to paste it into a formatter and let it indent and validate for you. Our JSON formatter pretty-prints nested objects and arrays and points to the exact line when a quote or comma is wrong, so you can see each of these six types laid out clearly.

FAQ

How many data types does JSON have? Six: string, number, object, array, boolean, and null. Every value in any JSON document is one of these, and objects and arrays can nest the others inside them to any depth.

Is null a data type in JSON? Yes. null is one of JSON’s six types and represents an intentional empty value. It is distinct from 0, from an empty string "", and from a key being absent, so treat each of those as a separate meaning.

Can JSON store dates? Not directly. JSON has no date type, so dates are stored as strings, usually in ISO 8601 format like "2026-08-17T09:00:00Z", and parsed back into a date object by your code.

Why must JSON strings use double quotes? The JSON spec defines a string as text in double quotes, so parsers reject single quotes. 'hello' is invalid JSON even though it looks fine in JavaScript. Object keys are strings too, so they also need double quotes.

#json#data#guide