How to use the CBOR encoder
- Paste JSON into the left pane. The CBOR bytes update as you type.
- Output: Hex, Base64, Hex dump, C array, JS Uint8Array or Python bytes.
- Copy or Download. The status bar compares the CBOR size with the minified JSON.
Example
[1, 2]
becomes
82 01 02
82 is an array of two items; 01 and 02 are the integers themselves, small enough to fit in the head byte. The same data in JSON takes five bytes.
How values are encoded
- Integers: major type 0 (unsigned) or 1 (negative), with the shortest argument size. Beyond 64 bits: tag 2 / 3 bignums.
- Floats: half (
f9) when exact, such as 1.5 or 65504.0; single (fa) when exact in 32 bits; double (fb) otherwise, such as 1.1. - Strings: major type 3, UTF-8.
- Arrays and objects: major types 4 and 5 with definite lengths, keys in the order you wrote them.
- true, false, null:
f5,f4,f6.
A JSON number without a fraction or exponent is an integer; with one (1.0, 2e3) it is a float, so the type survives the round trip. Every JSON-representable example in Appendix A of RFC 8949 encodes to exactly the bytes the RFC lists.
When it helps
Build test vectors for a WebAuthn or COSE implementation, fixtures for an IoT device, or payloads for a CoAP endpoint. Check the result with CBOR to JSON, compare its size with JSON to MessagePack, and validate your input first with the JSON Formatter. For numbers in other bases while you read the hex, the Number Base Converter is handy.
CBOR or MessagePack?
Both are compact binary encodings of the JSON data model and produce similar sizes. CBOR is an IETF standard (RFC 8949) with tags for dates, bignums and URIs, which is why WebAuthn, COSE and many IoT protocols chose it. MessagePack is simpler and very common in caches, logs and RPC. If you are free to choose, pick the one your libraries and partners already use.
Limits
JSON has no byte strings, tags, undefined or special simple values, so the encoder never produces them; use a CBOR library if you need those.
Frequently asked questions
Does it produce the shortest encoding?
Yes. Integers use the shortest head (the value itself below 24, then 1, 2, 4 or 8 bytes), and floats use a 16-bit half when it holds the value exactly, then 32-bit, then 64-bit, as RFC 8949's preferred serialization recommends.
What happens with integers bigger than 64 bits?
They are written as bignums: tag 2 for positive and tag 3 for negative values, followed by the big-endian magnitude. The JSON parser keeps them exact, so nothing is rounded.
Is the output deterministic?
The same JSON always gives the same bytes. Map keys keep the order they have in your JSON; RFC 8949's core deterministic encoding also sorts keys, so sort them first if a verifier requires that.
Which output formats are available?
Spaced hex, Base64, an xxd-style hex dump, and byte arrays for C, JavaScript and Python.
Is my JSON uploaded?
No. Encoding happens entirely in your browser.
Last updated