CBOR, Explained
iLoveConverter Team 2 min read
On this page
CBOR (Concise Binary Object Representation) is a compact binary serialization format standardized in RFC 7049. It’s JSON’s binary cousin — it represents the same data structures (maps, arrays, strings, numbers, booleans, null) but as binary bytes instead of text. This makes it 30–50% smaller than JSON, zero-copy friendly, and ideal for IoT, embedded devices, and bandwidth-sensitive APIs where every byte counts.
Technical details
CBOR uses major type encoding — the first 3 bits of each byte declare the type (uint, negint, bytes, text, array, map, tag, simple/float). Numbers pack efficiently: small integers fit in a single byte; 64-bit floats get encoded in 9 bytes. CBOR supports indefinite-length arrays (streaming), tags (for timestamps, URIs, dates), and has a deterministic encoding variant for hashing. No whitespace, no delimiters, no escaping — just typed bytes.
| Feature | CBOR | JSON | MessagePack | Protocol Buffers |
|---|---|---|---|---|
| Format | Binary | Text | Binary | Binary |
| Size (vs JSON) | 40–70% | 100% | 50–80% | 20–40% |
| Schema | None | None | None | Required |
| Type safety | Moderate | Weak | Moderate | Strong |
| Streaming | Yes | Partial | No | No |
| Deterministic encoding | Yes | No | No | Yes |
Conversion
CBOR ↔ JSON conversion is straightforward — every CBOR value maps to a JSON type. Use cbor2json CLI, the cbor Python library, or browser CBOR readers. CBOR → MessagePack is also clean; the tricky part is tags (which CBOR has but MessagePack doesn’t — they need manual mapping or dropping).
Common problems
- Human-unreadable. Binary format — impossible to debug without tools.
- Floating point precision. CBOR supports 16-bit floats; some languages have trouble round-tripping them.
- Limited tooling. While the spec is mature, CBOR libraries exist in most languages but fewer than JSON.
FAQ
Why use CBOR instead of JSON?
Size and speed. CBOR encodes/decodes faster, produces smaller payloads, and handles binary data natively without base64 encoding overhead. Best for IoT, embedded, or bandwidth-constrained APIs.
Is CBOR deterministic?
Yes — there’s an RFC 8749 section specifying deterministic CBOR encoding (canonical byte ordering). This matters if you want to hash CBOR payloads for signatures or content addressing.
What’s the difference between CBOR and MessagePack?
CBOR has tags (semantic hints for timestamps, URIs, dates), indefinite-length streaming, and a deterministic spec. MessagePack is simpler and slightly more compact for integers. Both are JSON-compatible. Choose CBOR when you need tags or determinism.
Can CBOR replace JSON everywhere?
Not for human-readable configuration. For APIs and storage, absolutely — it’s faster and smaller. Protocol Buffers and FlatBuffers beat CBOR when you have a schema to validate against.
Does WebAuthn use CBOR?
Yes — WebAuthn authenticator responses are CBOR-encoded. It’s also used in COSE (CBOR Object Signing and Encryption) for signed tokens and IoT certificates.
Try it yourself — free, right in your browser
Everything mentioned in this guide runs locally on this site: no upload, no watermark, no sign-up.
Format deep-dives: CBOR (.cbor) , MSGPACK (.msgpack)