Skip to main content

Object

RFC 8259 §4

{ "key": value, "key": value, ... }

A JSON object is an unordered collection of zero or more key-value pairs enclosed in curly braces. Keys must be strings. Duplicate keys are allowed by the spec but produce undefined behavior. Object key order is not guaranteed by RFC 8259 – do not rely on insertion order.

Description

JSON objects consist of string keys paired with values of any type, separated by colons, with pairs separated by commas. The RFC 8259 spec says implementations SHOULD generate objects with unique keys but parsers MUST accept duplicate keys (with undefined behavior on duplicates).

Key ordering: RFC 8259 explicitly states that objects are unordered. JavaScript V8, Python dicts (3.7+), and most modern implementations do preserve insertion order as an implementation detail, but this is not guaranteed by the spec. Never rely on object key order.

Key naming conventions: most APIs use camelCase (userId), snake_case (user_id), or kebab-case (user-id). Pick one and be consistent. JSON Schema lets you enforce key naming patterns.

Examples

LabelValue
Empty{}
Simple{"name": "Alice", "age": 30}
Nested{"user": {"id": 1, "email": "[email protected]"}}
Mixed values{"id": 1, "tags": ["a", "b"], "meta": null}

Common Gotchas

!

Key order is not guaranteed by the spec – do not rely on JSON.stringify() key order for hashing

!

Keys must be strings – {1: 'value'} is not valid JSON (1 is a number, not a string key)

!

Duplicate keys are technically legal but produce undefined behavior – most parsers use last-value-wins

!

Trailing comma not allowed: {"a": 1,} is invalid JSON

!

No comments – {"key": 1 // comment} is not valid JSON

See Also