Loading CBOR Validator...
Please wait a moment

How to Check CBOR Bytes

CBOR is binary, so a small slip in an encoder, a value cut off in a log, or bytes mangled by a text-only channel can be hard to spot by eye. Paste the bytes here to find out whether a decoder will accept them, and if not, where it goes wrong.

Step 1

Paste or upload the CBOR

Paste the bytes as Base64 or Hex and set the switch above the editor to match, or upload a .cbor or .bin file. Sample loads a small valid map.

Step 2

Wait a moment for the check

The bytes are checked shortly after you stop typing. While the check for new input is running, the result panel says Checking… instead of showing the previous verdict.

Step 3

Read the verdict

Valid CBOR shows the size, what the top-level value is, how many data items it holds and how deep it nests. Invalid CBOR names the problem and the byte offset where it starts, or the line and column of a bad Base64 or Hex character.

Step 4

Look at the warnings and fix the encoder

Amber warnings point at data that is well-formed but still not valid, such as a map that repeats a key. Fix the code that produced the bytes, then paste the new output to check it again.

What the check covers

Reported as invalid

  • Data that ends in the middle of a value
  • Lengths larger than the bytes that follow
  • Reserved header values (low bits 28–30)
  • Text strings that are not valid UTF-8
  • A break byte (0xff) outside an indefinite-length item
  • Indefinite-length strings with chunks of the wrong type
  • Leftover bytes after the value that are not CBOR themselves
  • Nesting deeper than 1,000 levels (too deep to check here)

Warned about or not checked

  • Warning: the same key twice in one map
  • Warning: tags 0, 1, 2, 3 and 32 holding the wrong type
  • Warning: several values back to back (a CBOR sequence)
  • Not checked: shortest or deterministic encoding
  • Not checked: CDDL schemas, COSE signatures, other tags

The rules come from RFC 8949, and sequences from RFC 8742. Once the bytes pass, read the values with CBOR to JSON or the CBOR Decoder.

Frequently Asked Questions

What makes CBOR invalid?

Most broken CBOR falls into a few groups. The data is cut off, so a length or a container promises more bytes than are there. A header byte uses one of the reserved values 28 to 30 in its low five bits, which no encoder should ever write. A text string holds bytes that are not valid UTF-8. A break byte (0xff) shows up where no indefinite-length array, map or string is open. An indefinite-length text string contains a chunk of a different type. Or there are extra bytes after the first complete value. Each of these is reported with the byte offset where the trouble starts.

What does this validator check, and what does it leave out?

It reads every byte the way RFC 8949 describes and fails on anything that is not well-formed. On top of that it warns about two things that are well-formed but not valid: a map with the same key twice, and the standard tags 0, 1, 2, 3 and 32 holding the wrong kind of value. It does not check that the encoding is the shortest or deterministic form, it does not compare the data against a CDDL schema, and it does not verify COSE signatures or the meaning of other tags.

Why does it say "Not a single CBOR value"?

The bytes hold two or more complete values back to back. That is a CBOR sequence (RFC 8742), which is fine for logs and streams, but a decoder that expects one value will either stop after the first one or complain about extra data. If you meant to send a list, wrap the values in an array before encoding.

My library accepts data this page rejects, or the other way round. Why?

Decoders differ at the edges. Many stop at a nesting limit (this page stops at 1,000 levels, some libraries much earlier), some quietly keep the last of two equal map keys, some reject non-shortest encodings in strict mode, and some refuse tags they do not know. Bytes this page calls well-formed can still be rejected by a stricter reader, and a lenient reader may accept bytes that break the rules here.

Are very large integers checked exactly?

Yes. Integers are read as text, not as JavaScript numbers, so uint64 values up to 18446744073709551615, int64 down to -9223372036854775808 and bignums in tags 2 and 3 are handled exactly. When the top-level value is a single integer, the details show it with every digit, for example 8901240544102066246.

Is my CBOR uploaded anywhere?

No. The bytes are decoded and checked in your browser, nothing is sent to a server and nothing is kept, so a reload starts with an empty editor. To see the values inside, open the same input in CBOR to JSON or the CBOR Decoder.