Understand JSON types and values
A practical guide to the six JSON value types, what JSON does not support, and how formatting or validation tools can change your data's meaning.
JSON looks simple, and its type system is small. Most problems come from the edges: numbers that lose precision, values that are not actually JSON, and tools that quietly rewrite data while formatting it. This guide covers the value types defined by the JSON standards (ECMA-404 and RFC 8259), how they differ from types in programming languages and JSON Schema, and what to check before you trust a formatter, minifier or validator with your data.
The six JSON value types
A JSON value is exactly one of six things. Four are primitive: string, number, boolean and null. Two are structured: object and array. Both structured types can contain any value, including other objects and arrays, which is how nested documents are built.
| Type | Written as | Notes |
| string | "text in double quotes" | Unicode text; double quotes only; certain characters must be escaped |
| number | 42, -3.5, 1e-7 | Decimal only; one type covers integers and fractions |
| boolean | true, false | Lowercase literals, never quoted |
| null | null | Lowercase literal meaning an intentionally empty value |
| object | {"key": value} | Unordered set of name/value pairs; names are strings |
| array | [value, value] | Ordered list; items may be of mixed types |
{
"name": "Sensor A",
"reading": 21.4,
"active": true,
"location": null,
"tags": ["indoor", "floor-2"],
"limits": { "min": -10, "max": 50 }
}
The example uses all six types: a string, a number, a boolean, null, an array of strings and a nested object. Whitespace between tokens (spaces, tabs, line feeds and carriage returns) carries no meaning, so the same document could be written on one line without changing any value.
What JSON does not support
Much invalid JSON comes from habits carried over from JavaScript or configuration formats. The following are not part of standard JSON:
- undefined: there is no such value; omit the key or use null
- NaN, Infinity and -Infinity: not valid numbers in JSON
- Hexadecimal, octal, leading zeros (such as 007) and a leading plus sign
- Single-quoted strings and unquoted object keys
- Comments of any kind
- Trailing commas after the last item in an object or array
- Dates, times, binary data and other rich types: these must be encoded as strings or numbers by convention, and the convention is not part of JSON itself
Some parsers accept a few of these anyway. Python's standard json module, for example, reads and writes NaN and Infinity by default unless told not to. Data that passes through a lenient parser may later fail in a strict one, so validating against the standard, not against whatever one library tolerates, avoids surprises.
Numbers: one type, uneven handling
JSON defines number as a decimal format with an optional fraction and exponent. It sets no limit on size or precision. Implementations do, however. RFC 8259 notes that IEEE 754 double-precision numbers are widely used and that integers between -(2^53)+1 and 2^53-1 can be exchanged reliably. Outside that range, many parsers round silently.
// JavaScript
JSON.parse("9007199254740993") // 9007199254740992
JSON.stringify(1.0) // "1"
JSON.stringify(1e2) // "100"
In the first line, the value read back is not the value written. The other two lines show that 1.0, 1 and 100 versus 1e2 are the same number to a parser, so formatting does not keep their original spelling. Large identifiers, such as database keys or account numbers, are often sent as strings precisely to avoid this. If the original digits matter, treat them as text.
Strings and escapes
Strings must use double quotes. Inside them, a double quote, a backslash and control characters must be escaped, using forms such as ", \, \n and \t. Any character can also be written as a \u escape with four hexadecimal digits; characters outside the Basic Multilingual Plane, including most emoji, take two \u escapes forming a surrogate pair. A raw é and the escape \u00e9 represent the same string, so a tool that switches between them changes the stored characters but not the value. RFC 8259 requires UTF-8 for JSON exchanged between systems that are not part of a closed ecosystem, and says a byte order mark must not be added.
Objects and arrays
Array order is meaningful: [1, 2] and [2, 1] are different values. Object member order is not guaranteed to be meaningful. Some libraries preserve insertion order and others do not, so code should not rely on it. Duplicate keys within one object are allowed by the grammar but discouraged by RFC 8259, which warns that behavior varies. Many common parsers, including JavaScript's JSON.parse and Python's json module, keep the last occurrence and discard earlier ones without warning.
JSON types versus JSON Schema types
Searches for "json type" often relate to JSON Schema, a separate specification that describes the expected shape of a document. Its type keyword accepts the six JSON types plus integer, which means a number with no fractional part. Integer is a schema constraint, not a seventh JSON value type. The distinction matters for validation. A syntax validator confirms that text is well-formed JSON. A schema validator checks whether that JSON matches agreed rules, such as a required field being a string. Passing the first does not imply passing the second.
What formatting and validation tools actually change
Pretty-printing and minifying are meant to change only insignificant whitespace, so the values stay identical. The risk depends on how the tool works. A tool that only adjusts whitespace between tokens leaves every character inside strings and numbers alone. A tool that parses the document into native data and writes it back out can alter the text in several ways:
- Numbers may be rounded or respelled, as shown above
- Escapes may be expanded or added, such as \u00e9 becoming é or the reverse
- Duplicate keys may collapse to a single entry
- Keys may be reordered, especially if a sort-keys option is enabled
- Non-standard input such as comments, trailing commas or NaN may be stripped, rejected or passed through, depending on the parser
A quick check is to format a small sample that includes a large integer, a number with a trailing zero, an escaped character and a duplicate key, then compare the output with the input. This shows whether a particular tool preserves the text or reserializes it. Avoid assuming that a tool handles your data privately or discards it afterward based on its appearance; look for a stated policy before pasting anything sensitive.
Will formatted JSON survive copying and sharing?
JSON is plain text, so it usually copies cleanly between code editors and terminals. Problems tend to come from destinations that treat it as prose. Word processors and some messaging or note-taking apps can replace straight double quotes with typographic curly quotes, which makes the JSON invalid. Line wrapping can also insert breaks inside long strings. Whether a specific app does this depends on its settings and version, so test the destination you actually use rather than assuming. Code blocks or file attachments usually avoid the issue where the destination offers them. Indented formatting makes structure easier to scan visually. How screen readers announce brackets, quotes and indentation depends on the reader and its punctuation settings, and no scoped test was available for this review. For readers using assistive technology, a short prose or table summary of the key fields alongside the raw JSON is a reasonable fallback.
Is a given transformation suitable?
Pretty-printing is suitable for reading, reviewing and debugging. Minifying is suitable for transmission and storage when size matters. Both are safe when the tool changes only whitespace, or when your data stays within the ranges and conventions that reserialization preserves. The decisive tradeoff is readability against exact textual fidelity. Keep the original, unmodified text when byte-for-byte content matters: signed payloads and hashes, large numeric identifiers, documents with intentional duplicate keys, or files that must later be diffed against a source. In those cases, compare outputs before relying on a formatter, or skip reformatting entirely.
Limits of this review
This guide draws on the published JSON standards and widely documented parser behavior. It does not test or evaluate any specific formatting tool, online validator, messaging app or screen reader. Behavior in those environments should be confirmed with a small test using your own data.