CBOR Decoder

Decode CBOR to JSON per RFC 8949: date-time tags rendered, half-floats, indefinite lengths and 64-bit integers, tested against the RFC's own example vectors.

The interactive tool loads here when JavaScript runs.

About this tool

What is the CBOR Decoder?

Paste CBOR bytes as hex or base64 and read them as JSON, decoded in your tab. CBOR is the binary JSON of the standards world: WebAuthn attestations, COSE and CWT tokens, CoAP payloads from IoT devices, and anything else built on RFC 8949 (STD 94, the 2020 revision of RFC 7049). The decoder is pinned against the RFC's own Appendix A example vectors in this site's test suite, so what it prints for -100, for the half-float 0xf90001 or for the tagged epoch 0xc11a514b67b0 is what the RFC says those bytes mean.

Everything JSON cannot say is tagged rather than dropped. Tagged items keep their tag number under $tag, with tag 0 (an RFC 3339 date-time string) and tag 1 (epoch seconds) rendered as readable date-times. Integers past 2^53 come back as exact $int64 decimal strings. Byte strings become $bytes hex previews instead of mojibake, CBOR's undefined and its numbered simple values survive as $undefined and $simple, and a map key that was an integer stays visible as "$key:1" instead of colliding into a stringified mess.

The format's quirks are handled where they bite: half-precision floats (the 16-bit kind JSON has no name for) decode per the RFC's reference algorithm, indefinite-length arrays, maps, text and byte strings run until their 0xff break code with chunk content joined, and trailing bytes after the first item are counted and reported, since CBOR sequences are just items back to back.

  • Hex or base64 input (URL-safe base64 included), decoded entirely in your browser
  • Pinned against RFC 8949 Appendix A example vectors in the test suite
  • Tags preserved as $tag, with tag 0 and tag 1 date-times rendered as ISO 8601
  • Half-precision floats decoded per the RFC's Appendix D algorithm
  • Indefinite-length arrays, maps and text strings handled to their break code
  • $int64 for integers past 2^53, $bytes for byte strings, $undefined, $simple and $key: for non-string map keys
  • Trailing-bytes count for CBOR sequences
Read the guide: How to Decode Binary Formats Without the Schema

Updated

How to use the CBOR Decoder

  1. Get the bytes: WebAuthn attestationObject fields arrive as base64url, CoAP and COSE payloads as hex in a packet capture, test vectors as hex in a spec. All of those paste straight in.
  2. Press Decode, or Load a sample to see a map holding a tag 0 date-time, a maximum uint64 and the RFC's Appendix A half-float.
  3. Read the JSON, following the $ tags where JSON ran out of words: $tag for tagged items, $int64 for exact big integers, $bytes for byte strings, $undefined and $simple for major type 7 values.
  4. Check the trailing-bytes warning: CBOR sequences (several items back to back) are legal and common, and the count tells you where the next item starts.
  5. Copy or download the JSON for the ticket or the test fixture.

Worked examples

An Appendix A vector, exactly as the RFC prints it

Input

a2 61 61 01 61 62 82 02 03

Output

{"a": 1, "b": [2, 3]}

0xa2 is a 2-pair map, 0x61 0x61 the one-byte text string "a", 0x01 the integer 1. This exact row sits in RFC 8949 Appendix A, and the site's test suite asserts this decoder reproduces it, along with -100 for 0x3863 and the other vectors.

Tag 1: an epoch timestamp made readable

Input

c1 1a 51 4b 67 b0

Output

{"$tag": 1, "epoch": 1363896240, "datetime": "2013-03-21T20:04:00.000Z"}

0xc1 tags the following item as epoch seconds (RFC 8949 section 3.4.2) and 0x1a514b67b0 is the uint32 1363896240, the RFC's own example value. The decoder keeps the raw number and adds the ISO 8601 rendering, which is the answer the investigation usually wants.

A half-precision float

Input

f9 00 01

Output

5.960464477539063e-8

Major type 7 with additional information 25 means an IEEE 754 half-precision float, a 16-bit format JSON has no literal for. 0x0001 is the smallest positive subnormal, and the decoded value matches RFC 8949 Appendix A digit for digit, computed by the same algorithm the RFC gives in Appendix D.

Indefinite lengths, closed by the break code

Input

9f 01 82 02 03 9f 04 05 ff ff

Output

[1, [2, 3], [4, 5]]

Both 0x9f arrays declare no length and run until their 0xff break, a form streaming encoders emit because they cannot know the count up front. The RFC prints this vector as [_ 1, [2, 3], [_ 4, 5]], the underscores marking which brackets were indefinite; the values are what matter here, and they match.

Background and insight

Every CBOR byte stream is built from one rule: the first byte of each item splits into a 3-bit major type and 5 bits of additional information. Major types 0 and 1 are unsigned and negative integers, 2 and 3 byte and text strings, 4 and 5 arrays and maps, 6 tags and 7 floats and simple values. The additional information either is the value, names how many length bytes follow, or (value 31) declares an indefinite length. One byte of structure per item is why a small CBOR document reads almost like its JSON twin: {"a": 1, "b": [2, 3]} is the nine bytes a2 61 61 01 61 62 82 02 03.

Tags are CBOR's extension mechanism and its biggest practical difference from MessagePack: a tag is a number prefixed to any item, giving it a registered meaning without changing the encoding. The RFC defines tag 0 (date-time string per RFC 3339) and tag 1 (epoch seconds, integer or float); IANA runs the registry for the rest. This decoder renders tags 0 and 1 as date-times and passes every other tag through as {"$tag": n, "value": ...}, because inventing semantics for unknown tags is how decoders lie.

Two more corners matter in real payloads. CBOR allows maps keyed by anything, and the RFC notes a valid map may even hold both 0 and 0.0 as keys; JSON objects cannot, so non-string keys are preserved here under a "$key:" prefix. And duplicate keys are well-formed but, per the RFC, not valid: a generic decoder keeps one instance, which is exactly what this one does, so a payload using duplicates as a smuggling trick reads the way most receivers would read it.

Common use cases

  • Decoding a WebAuthn attestation or COSE key

    The attestationObject and credentialPublicKey are CBOR maps, often with integer keys; those survive here as $key:1, $key:3 and so on, matching the COSE parameter tables instead of vanishing.

  • Reading an IoT device's CoAP payload

    Constrained devices favour CBOR for the same reason they favour UDP. Hex from a packet capture decodes locally, with half-floats, the format sensors actually use for readings, handled correctly.

  • Verifying an encoder against the RFC

    Encode a value in your language, paste the hex, and compare against what Appendix A says those bytes mean; this decoder is pinned to those vectors, so it works as a neutral referee.

  • Working through a CWT or other signed token

    The COSE envelope and its payload are nested CBOR; decoding the layers one at a time shows the protected headers, the claims and where the signature bytes start.

  • Comparing CBOR against MessagePack for a protocol decision

    Encode the same document both ways and look at the output side by side; the tags, the integer keys and the indefinite lengths are where the two formats genuinely differ.

Tips and limitations

  • Base64url from WebAuthn pastes directly: the URL-safe alphabet is translated before decoding, so attestationObject strings need no preprocessing.
  • Integer map keys are normal CBOR, not corruption: COSE deliberately keys its maps with small integers to save bytes. The $key: prefix keeps them distinct from the string keys JSON forces.
  • Trailing bytes are not an error. A CBOR sequence is several items concatenated; decode, trim the reported count from the front, and decode again.
  • Indefinite-length text strings are reassembled from their chunks per the RFC. Indefinite-length byte strings are rare outside streaming encoders and currently come back as an empty $bytes preview rather than the joined bytes; definite-length byte strings, the overwhelmingly common case, are unaffected.
  • Duplicate map keys collapse to a single entry, which matches what the RFC says generic decoders do; if you suspect a payload uses duplicates deliberately, inspect the hex around the map header in the hex editor on this site.
  • If the output looks shifted or half-sensible, try the MessagePack decoder: the two formats are cousins and a mislabelled payload decodes as noise in one and cleanly in the other.

Sources and further reading

  1. RFC 8949: Concise Binary Object Representation (CBOR), IETF. STD 94: major types, tags, indefinite lengths, Appendix A vectors, Appendix D half-float code
  2. Concise Binary Object Representation (CBOR) Tags, IANA. The registry a $tag number resolves against

Frequently asked questions

How do I decode CBOR to JSON in the browser?

Paste the hex or base64 here and press Decode; nothing is uploaded. The output is JSON with $-tagged wrappers wherever CBOR says more than JSON can: tags, big integers, byte strings, undefined, simple values and non-string map keys all stay visible instead of being flattened away.

What are CBOR major types?

The 3-bit class in every item's first byte: 0 unsigned integer, 1 negative integer, 2 byte string, 3 text string, 4 array, 5 map, 6 tag, 7 floats and simple values. The remaining 5 bits carry the value or the length, which is why small items cost one byte of structure.

What do CBOR tags 0 and 1 mean?

RFC 8949's two built-in date-time tags: tag 0 wraps an RFC 3339 text date-time, tag 1 wraps epoch seconds as an integer or float. This decoder renders both as ISO 8601 alongside the raw value. Other tag numbers come from the IANA registry and are passed through as $tag so their meaning stays yours to resolve.

Why does my decoded CBOR map have keys like "$key:1"?

CBOR maps may be keyed by any type, and protocols like COSE use integer keys on purpose. JSON objects only allow strings, so this decoder prefixes non-string keys with $key: to keep 1 distinct from "1" instead of silently merging them.

What is a half-precision float in CBOR?

A 16-bit IEEE 754 float, written 0xf9 plus two bytes. CBOR includes it for constrained devices where sensor readings do not need 32 bits. JSON has no such type, so the value is decoded to a regular number using the algorithm RFC 8949 provides in Appendix D.

What does the 0xff byte mean in CBOR?

The break stop code. Arrays, maps, byte strings and text strings may be written with indefinite length (additional information 31) when the encoder cannot know the count up front, and 0xff marks where each one ends. Outside that position, 0xff would start a different item, so context decides its meaning.

Is CBOR the same as MessagePack?

No, though they solve the same problem and look similar in a hex dump. CBOR is an IETF standard (RFC 8949) with a tag registry, indefinite lengths and half-floats; MessagePack predates it and uses an ext mechanism instead of tags. A payload from WebAuthn, COSE or CoAP is CBOR; one from Redis, Fluentd or a game server is usually MessagePack.

Is there an in-depth guide to the CBOR Decoder?

Yes. “How to Decode Binary Formats Without the Schema” covers the background, how it works, common pitfalls and worked examples. Read the full guide.