How to Format CBOR
Encoders, test vectors and RFC examples tend to hand you CBOR either as one long line of diagnostic notation or as raw bytes in Hex. Paste either one below to get it laid out one item per line.
Paste diagnostic notation or CBOR bytes
Paste minified diagnostic notation, or the CBOR bytes as Hex or Base64. You can also upload a .cbor file or a text file holding any of these. The Sample button loads a one-line example with a byte string, two tags and an indefinite-length map.
Read the indented result
About half a second after you stop typing, the output shows the data with 2-space indentation, one item per line. If something is wrong, you get the line and column of the problem instead.
14.50 and strings like "00501" keep their exact spelling. Comments are left out.h'…', and tags, undefined and indefinite lengths appear as they are in the data.Copy or download it
Copy puts the formatted text on your clipboard; Download saves it as formatted-cbor.txt.
Frequently Asked Questions
What is CBOR diagnostic notation?
It is the text form of CBOR described in section 8 of RFC 8949. It looks like JSON but can also write the things JSON has no syntax for: byte strings such as h'00ff', tags such as 1(1363896240), undefined, simple(16), indefinite-length arrays written [_ 1, 2], and map keys that are numbers. RFCs, COSE and CWT examples and most CBOR debugging tools print data this way.
What can I paste: text or bytes?
Either. Diagnostic notation (or plain JSON) is re-indented as text. CBOR bytes written as Hex (a1 61 61 01, 0xa1, 0x61, … or one long run of digits) or as Base64 (plain or URL-safe, with or without padding) are decoded and printed as diagnostic notation. A binary .cbor file you upload is shown as Base64 and decoded the same way. The badge above the output says which reading was used.
Does formatting change any values?
No. Text you paste is only re-spaced: every number, string and h'…' literal keeps the exact spelling you typed, so 14.50 stays 14.50 and 8901240544102066246 keeps all its digits. The one thing that is dropped is comments (/ … / and # …), and a note says so when that happens.
How are numbers shown when I paste Hex or Base64?
Integers are printed with every digit, including 64-bit values like -9223372036854775808 and 18446744073709551615. Floats always show a decimal point or an exponent (2.0, not 2), so you can tell them from integers, and NaN, Infinity and -0.0 are written out. A bignum stays as its tag, for example 2(h'400000000000000000'), exactly as it is stored.
How is this different from CBOR to JSON?
CBOR to JSON gives you JSON you can load in any program, so CBOR-only types have to be translated: byte strings become Base64 text and tags become small objects. This formatter keeps the CBOR view instead, with h'…' bytes, tags, undefined and number keys left as they are, which is what you want when you are debugging an encoder or writing documentation.
What does an error like "Line 1, column 12" mean?
For diagnostic notation it points at the spot where the text stops making sense, such as a missing comma, an unclosed bracket or a word without quotes. For Hex and Base64 it names the character that does not belong, or says the data looks cut off when the bytes end in the middle of a value.
Is my data sent anywhere?
No. Formatting and decoding run in JavaScript in your browser and the download is built on your own machine. Nothing is uploaded and nothing is kept, so a reload starts with an empty editor.
The notation is defined in RFC 8949, section 8. For plain JSON, the JSON Formatter has more options.
Related Tools
CBOR to JSON
Convert CBOR binary data to JSON format with Base64 and Hex support
JSON to CBOR
Convert JSON data to CBOR binary format
CBOR Fixer
Fix broken CBOR data automatically, repair malformed binary object representations and structural errors
CBOR Encoder
Encode JSON, YAML, XML, CSV to CBOR binary format with Base64 and Hex output
CBOR Decoder
Decode CBOR binary to JSON, YAML, XML, CSV formats with Base64 and Hex input
CBOR Validator
Validate CBOR binary data structure and integrity