JSON Data Types Explained With Examples

JSON Data Types Explained With Examples

Every value in a JSON document belongs to one of a small, fixed set of data types. Unlike programming languages, which often have dozens of types (integers, floats, dates, sets, tuples, and more), JSON keeps things deliberately simple — just six types cover everything. Understanding them properly makes it much easier to read unfamiliar JSON, debug type-related bugs, and write valid JSON of your own.

This guide walks through each type individually, with real examples, plus the quirks and edge cases that catch people off guard.

The Six JSON Data Types

  1. String
  2. Number
  3. Boolean
  4. Null
  5. Object
  6. Array

That’s the complete list. Every JSON value, no matter how deeply nested, is built from these six types.

JSON Data Types

1. String

A string is text, always wrapped in double quotes:

{"name": "Kings Tools"}

Key rules:

  • Only double quotes are valid — single quotes are not JSON
  • Special characters must be escaped with a backslash: \" for a quote, \\ for a backslash, \n for a newline
  • Strings can be empty: "" is valid

Common mistake: treating numeric-looking text as a number when it should stay a string. A phone number, ZIP code, or ID with a leading zero should usually be stored as a string ("07123") rather than a number (07123), since JSON numbers can’t have leading zeros and the value would be technically invalid — or worse, silently reinterpreted incorrectly.

2. Number

Numbers in JSON have no quotes and cover both integers and decimals — there’s no separate “float” or “int” type at the syntax level:

{"age": 29, "price": 19.99, "temperature": -4}

Key rules:

  • No leading zeros (except the number 0 itself)
  • No + sign for positive numbers
  • Decimals require a digit before the decimal point (0.5, not .5)
  • Scientific notation is supported: 6.02e23

Common mistake: assuming JSON preserves the distinction between an integer and a float. 5 and 5.0 are both simply “numbers” in JSON — whether your programming language treats the parsed result as an int or a float depends on that language’s own JSON library, not on JSON itself. This occasionally causes subtle bugs when data passes between languages with different type systems.

3. Boolean

A boolean is either true or false, written lowercase and without quotes:

{"isActive": true, "isDeleted": false}

Common mistake: capitalizing it as True or False (valid in Python) or wrapping it in quotes as "true" (which makes it a string, not a boolean — and most code checking if (value === true) will fail against the string "true").

4. Null

null represents the deliberate absence of a value — not the same as an empty string, zero, or false:

{"middleName": null}

Common mistake: confusing null with undefined. JSON has no concept of undefined at all — that’s a JavaScript-specific value with no JSON equivalent. If you’re generating JSON from JavaScript and a value is undefined, most serializers will simply omit that key entirely rather than writing "key": undefined, since that would be invalid JSON.

It’s also worth distinguishing null from an empty string "" or the number 0 — these represent different things. null typically means “this field intentionally has no value,” while "" or 0 are real, present values that happen to be empty or zero.

5. Object

An object is an unordered collection of key-value pairs, wrapped in curly braces:

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

Key rules:

  • Keys must always be double-quoted strings
  • Values can be any of the six JSON types, including nested objects
  • Keys within the same object should be unique — duplicate keys are technically tolerated by some parsers but aren’t spec-compliant and produce unpredictable results

Objects can nest inside other objects to represent hierarchical data:

{
  "user": {
    "name": "Alex",
    "address": {
      "city": "Lahore",
      "country": "Pakistan"
    }
  }
}

6. Array

An array is an ordered list of values, wrapped in square brackets:

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

Key rules:

  • Order is preserved and meaningful — unlike object keys, array position matters
  • Arrays can hold any mix of the six types, including other arrays and objects
  • An empty array [] is valid

Mixed-type arrays are perfectly valid JSON, even though they’re unusual in day-to-day use:

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

More commonly, arrays hold objects that share the same structure — this is one of the most frequent patterns in real-world JSON, especially in API responses:

{
  "users": [
    { "id": 1, "name": "Alex" },
    { "id": 2, "name": "Sam" }
  ]
}

Objects vs. Arrays: When to Use Which

A common point of confusion for beginners is deciding whether a piece of data should be an object or an array. The distinction comes down to this:

  • Use an object when you’re describing named properties of one thing (a person’s name, age, and email)
  • Use an array when you have an ordered collection of similar items (a list of users, a list of tags, a list of scores)

A good test: if you’d naturally refer to items by position (“the first user,” “the third tag”) rather than by name (“the user’s email”), it belongs in an array.

Type Coercion Pitfalls

Because JSON has fewer types than most programming languages, converting JSON into a language’s native types can introduce subtle bugs:

  • A JSON number like 9007199254740993 may lose precision when parsed into a language that represents all JSON numbers as 64-bit floating point (this is a known limitation in JavaScript specifically)
  • A JSON string that looks like a number ("42") stays a string unless your code explicitly converts it — comparing "42" === 42 will be false in JavaScript, for example
  • Dates have no native JSON type at all — they’re almost always represented as strings (commonly ISO 8601 format, like "2026-08-02T10:00:00Z") and need to be explicitly parsed back into a date object by whatever code consumes the JSON

Checking Your JSON’s Structure

When you’re working with a large or unfamiliar JSON payload, it’s easy to lose track of which values are strings versus numbers, or which fields are objects versus arrays — especially in minified JSON with no formatting at all. Running it through our JSON Formatter and Validator beautifies the structure into properly indented form, which makes the type of each value, and how everything nests together, immediately clear at a glance. If you’re still getting comfortable with the underlying syntax rules referenced throughout this guide, our JSON syntax guide covers those in full detail.

Summary

JSON’s six data types — string, number, boolean, null, object, and array — are deliberately minimal compared to most programming languages, which is exactly what makes JSON so portable across different systems. The type-related bugs that do come up almost always trace back to a handful of predictable mismatches: strings vs. numbers, null vs. undefined, or precision loss in very large numbers. Once you know what to watch for, working confidently across these six types becomes second nature.

Similar Posts

Leave a Reply

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