Skip to main content
4

Array

0x80 – 0x9b (0x9f indefinite)RFC 8949

CBOR major type 4 encodes arrays (ordered sequences of data items). The argument gives the item count, followed by that many data items. 0x83 0x01 0x02 0x03 = array [1, 2, 3]. Arrays can contain mixed types and can be nested. Indefinite-length arrays use 0x9f...0xff.

Encoding

Initial byte: 0b100_XXXXX. Argument = item count. Followed by items.

CBOR arrays work like JSON arrays but use a length prefix instead of brackets. 0x80 is an empty array. 0x81 with one following item is a one-element array. The count is the number of data items, not bytes.

Arrays can contain any CBOR data items including nested arrays and maps. CBOR has no restriction on mixed types in arrays.

Indefinite-length arrays (0x9f) are useful for streaming: the encoder can start writing array items before knowing the total count, terminating with the break code 0xff. This is common in CoAP (constrained devices) where computing total length upfront may require buffering.

Examples

LabelHexValue
Empty80[]
[1,2,3]83 01 02 03[1, 2, 3]
[1,[2,3]]82 01 82 02 03[1, [2, 3]]

See Also