Skip to content
uencoder

CBOR

CBOR (Concise Binary Object Representation) is a binary form of JSON, standardized in RFC 8949, more compact and supporting more data types.

Purpose

To provide a more compact binary encoding than JSON for bandwidth- and storage-constrained scenarios.

Mechanism

Every data item starts with a tag byte: the high 3 bits give the major type (0-7) and the low 5 bits the additional information. Major types 0-2 are unsigned integers, negative integers, and byte strings; 3 is a text string; 4-5 are arrays and maps; 6 is tags (semantic tagging); 7 is floats and simple values. Extension tags support dates, URLs, bignums, and more.

Use cases

  • CoAP IoT protocol
  • WebAuthn credential data
  • IPLD (the IPFS data model)
  • Sensor data transport

Examples

  • Input
    {"a":1}
    Output
    A1 61 61 01

    CBOR encoding of a one-pair map

Common errors

Confusing CBOR and MessagePack encoding details
They differ; parse with each specification

Related terms

Related tools

References