JSON objects and arrays
How JSON objects (dictionaries) and arrays differ, what formatting and conversion actually change, and when each structure suits your data.
JSON has two container types. An object holds named values, and an array holds values in sequence. Most questions about storing a dictionary in JSON come down to which container fits the data. A second question is whether formatting, validating or converting the data keeps its meaning. This review covers both, using the JSON specification's documented rules and the behavior of common parsers.
The short answer: objects for named lookup, arrays for order
Use a JSON object when each value is identified by a name and you look values up by that name. This is the JSON equivalent of a dictionary, map or hash. Use an array when position matters, when items can repeat, or when you have a list of similar records. In practice, a list of records is usually an array of objects. A lookup table is usually an object whose values are objects.
The decisive tradeoff is order versus keyed access. The JSON specification defines an object as an unordered collection of name/value pairs, so a consumer is not required to keep key order. An array is an ordered sequence, so its order is part of the data. If order carries meaning, an object is the wrong container, even if your current parser happens to preserve it.
Plain text, or a simple table, is the better choice when the audience is people rather than programs. Examples include a summary in an email, documentation prose, or a report for non-technical readers. JSON is built for machine exchange. Its punctuation makes it slower to read than a sentence or a table, and that cost buys nothing if nothing will parse it.
What a JSON object is
An object is written in curly braces. It contains zero or more name/value pairs separated by commas, and a colon separates each name from its value. Names must be strings in double quotes. A value can be a string, number, object, array, true, false or null.
{
"id": 42,
"name": "Ada",
"active": true,
"tags": ["admin", "editor"],
"manager": null
}
The specification says names within an object should be unique, but it does not strictly require this. When a key is duplicated, results depend on the implementation. Python's json module and JavaScript's JSON.parse both keep the last value, but other parsers may reject the input or behave differently. Treat duplicate keys as an error in your own data, and do not assume a syntax validator will flag them.
What a JSON array is
An array is written in square brackets. It contains zero or more values separated by commas. Values are identified by position, not by name. They can repeat, and they do not have to share a type, although arrays of one consistent type are easier to process.
[
{"id": 42, "name": "Ada"},
{"id": 7, "name": "Grace"},
{"id": 42, "name": "Ada"}
]
This array has three entries, and the first and last are identical. That is valid, and the order of the three entries is part of the data.
Difference between a JSON object and a JSON array
| Property | Object | Array |
| Delimiters | Curly braces { } | Square brackets [ ] |
| How values are identified | By string name | By position |
| Order | Not guaranteed by the specification | Guaranteed and meaningful |
| Duplicates | Keys should be unique; behavior with duplicates varies | Repeated values are allowed |
| Typical mapping in code | Dictionary, map, plain object | List, array, sequence |
| Typical use | One record, settings, lookup by key | Lists, sequences, collections of records |
Storing a dictionary in JSON
Most languages convert a JSON object into their native dictionary type, and convert it back. Python's json.loads returns a dict, and JavaScript's JSON.parse returns a plain object. The JSON side is narrower than many dictionary types, though, so the round trip is not always exact.
- JSON keys are always strings. Python's json.dumps converts integer, float, boolean and None keys to strings, and those keys come back as strings after loading.
- Keys that cannot become strings, such as Python tuples, raise an error by default rather than being converted.
- Values that JSON has no type for, such as dates, sets or binary data, must be encoded in some agreed way, for example as strings or arrays. The receiving side has to know that convention.
>>> import json
>>> json.dumps({1: "a", 2: "b"})
'{"1": "a", "2": "b"}'
>>> json.loads(json.dumps({1: "a"}))
{'1': 'a'}
For a collection of records, there are two common shapes: an array of objects, or an object keyed by an identifier. The keyed object gives direct lookup and enforces one entry per key. The array keeps order and allows the same entry to appear more than once.
{
"42": {"name": "Ada"},
"7": {"name": "Grace"}
}
The keyed form changes more than the shape. Duplicate records collapse into one, and the original order is no longer guaranteed. If the id lives only in the key, it is also no longer part of each record. When converting between the two shapes, decide in advance which of these losses are acceptable.
What formatting and validation actually change
In JSON tools, formatting means arranging whitespace, not changing fonts or characters. Pretty-printing adds indentation and line breaks, and minifying removes them. The specification treats whitespace between tokens as insignificant, so either operation alone leaves the data unchanged. Whitespace inside a string value is part of the string and must not be touched.
Many formatters work by parsing the input and serializing it again rather than only adjusting whitespace. That step can change the stored text while keeping the same meaning in some cases, and it can lose information in others:
- Key order can change. In JavaScript, keys that look like non-negative integers are listed first in ascending numeric order. As a result, parsing and re-serializing {"b":1,"2":2,"1":3} produces {"1":3,"2":2,"b":1}.
- Number formatting can change. In JavaScript, 1.0 is re-serialized as 1.
- Precision can be lost. JavaScript stores numbers as 64-bit floats, so integers above 9007199254740991 can be silently altered. For example, 9007199254740993 parses as 9007199254740992.
- Escapes can be rewritten. A sequence such as \u00e9 may come back as the literal character é. The string is equivalent, but the bytes differ.
- Duplicate keys can disappear, because only one value survives parsing.
If any of these matter, check whether the tool preserves the original text or re-serializes it. Common cases include large identifiers, signed payloads that are compared byte for byte, and files under version control where diffs should stay small. The tool's documentation or a quick test with a known input will show which. A formatter's appearance does not reveal what it does with your data, including whether it sends input to a server. Check its documentation rather than assuming.
Validation is a separate step. A syntax validator confirms that the text is well-formed JSON. It does not confirm that the right fields are present or have the right types. That requires a schema or application-level checks.
Readability and usability after copying or sharing
JSON is strict about the characters outside its strings, so sharing it through anything other than plain text can break it. These are the documented rules that copied JSON most often violates:
- Only straight double quotes are valid. Curly quotes inserted by rich-text editors or autocorrect make the JSON invalid.
- Only space, tab, line feed and carriage return count as whitespace. Non-breaking spaces outside strings are invalid.
- Comments and trailing commas are not allowed in standard JSON, even though some editors and configuration formats accept them.
- Single-quoted strings and unquoted keys are JavaScript syntax, not JSON.
To share JSON that someone will paste back into a program, send it as a file or inside a code block, and validate it after it arrives. When it is meant to be read rather than parsed, pretty-printed output is easier to scan. For non-technical readers, a table or a short prose summary is usually clearer than nested braces. In that case, provide the summary alongside the JSON rather than instead of it, so the machine-usable version is not lost.
This review has no tested evidence on how specific screen readers, messaging apps or search tools handle JSON, so it makes no claims about any particular product. Deeply nested punctuation is generally hard to follow when read aloud. Where accessibility matters, a plain-text or tabular equivalent of the key information is the safer option, and it should be tested with the assistive technology your readers actually use.
Choosing between them
- One record with named fields: object.
- Lookup by a unique key, where order does not matter: object.
- Ordered items, possible duplicates, or a list of similar records: array, usually an array of objects.
- Order matters and keyed lookup is also needed: an array of objects with an id field, with the index built in code.
- The reader is a person and nothing will parse the data: plain text or a table.