Skip to main content
5

Map

0xa0 – 0xbb (0xbf indefinite)RFC 8949

CBOR major type 5 encodes maps (key-value pairs). The argument gives the pair count. Keys and values can be any CBOR type – not just strings. 0xa2 0x61 0x61 0x01 0x61 0x62 0x02 = {"a":1, "b":2}. Integer keys are common in CBOR to reduce message size.

Encoding

Initial byte: 0b101_XXXXX. Argument = pair count. Followed by key-value pairs.

CBOR maps differ from JSON objects in one critical way: keys can be any CBOR type, not just strings. Integer keys are common in CBOR-based protocols to minimize message size: {0: value, 1: value} is far smaller than {"algorithm": value, "key_ops": value}.

COSE (RFC 9052) and CWT (RFC 8392) use integer keys extensively. For example, COSE header parameter 1 = alg (algorithm), 3 = content_type, 4 = kid (key ID).

Map key uniqueness: RFC 8949 RECOMMENDS unique keys (avoid duplicates) but does not require it. Definite-length maps declare the pair count. Indefinite-length maps (0xbf) terminate with break 0xff.

Examples

LabelHexValue
Emptya0{}
{"a":1}a1 61 61 01{"a": 1}
Integer keysa2 00 01 01 02{0: 1, 1: 2} (integer keys)
{"a":1,"b":2}a2 61 61 01 61 62 02{"a":1,"b":2}

See Also