jsontoolskit.org
JSON and JSON Schema utilities, in the browser
Say hi →

JSON ↔ CBOR

RFC 8949 · encode · decode · hex, base64, byte array or the binary itself

CBOR is the binary JSON that standards bodies actually reference: WebAuthn credentials, COSE signatures, CoAP payloads and most constrained-device protocols are CBOR underneath. Paste JSON to see the bytes it becomes, or paste the hex out of a debugger and read it back.

Paste JSON, or paste hex / base64 to decode.

How to use it

  1. Paste JSON. The output pane shows the encoded bytes and the status line compares them with the minified JSON.
  2. Pick the view you need — hex to paste into a test, base64 for a config or a header, byte array for source code.
  3. Download writes the real binary as data.cbor, not the hex view of it.
  4. Going the other way, switch Direction to decode and paste hex or base64 — it works out which one you gave it.

How CBOR writes a value

Every item starts with one byte split in two: the top three bits are the major type and the bottom five are an argument. Arguments 0–23 are the value itself; 24, 25, 26 and 27 mean "the next 1, 2, 4 or 8 bytes hold it"; 31 means "indefinite length, read until a break byte".

The parts JSON has no word for

Decoding CBOR into JSON runs into three things JSON cannot express, and each is handled explicitly rather than quietly dropped:

Options

float32 where exact

A non-integer number is float64 by default: nine bytes. Ticked, values that survive a round trip through single precision unchanged are written as float32 instead, halving that. 1.5 qualifies; 0.1 does not, and stays 64-bit rather than losing precision to save four bytes.

Canonical map order

RFC 8949 §4.2.1 defines a deterministic encoding where map keys are sorted by their encoded bytes — which means shorter keys first, and only then bytewise. That is not alphabetical: z sorts before aa. Tick this when the bytes have to be reproducible across implementations, which is the case whenever they are going to be signed or hashed. Leave it off and insertion order is preserved.

Drop null-valued keys

Omits keys whose value is null before encoding. Useful against a schema where absent and null mean the same thing, and destructive where they do not.

CBOR or MessagePack?

They solve the same problem and are close in size — usually within a byte or two of each other on the same document. Choose CBOR when a specification tells you to: it is an IETF standard with a defined deterministic encoding, a tag registry, and an extension model that other standards build on (COSE, CWT, WebAuthn). Choose MessagePack when you are picking for yourself and want the widest set of mature libraries. Encode the same document in both and compare the byte counts in each status line — on your data, not on a benchmark.

Limits