Loading CBOR Encoder...
Please wait a moment

How to Encode Data to CBOR

Step 1

Pick the input format

CBOR (Concise Binary Object Representation) holds the same kinds of values as JSON, so most data you already have can go straight in. This page is for when it isn't JSON yet: a YAML config, an XML export, a CSV sheet or a single line of text. If you only ever start from JSON, the JSON to CBOR converter does the same job with a few more checks for JSON-specific mistakes.

•
Select format: Click JSON, YAML, XML, CSV or Text above the input editor. The tab decides how your text is read, so a YAML file pasted under JSON shows an error.
•
Paste or upload: Paste into the editor, or click Upload to open a .json, .yaml, .yml, .xml, .csv or .txt file.
•
Try the sample: Sample fills the editor with a small record in whichever format is selected.

Example: JSON input

{
  "name": "Maeve",
  "age": 30,
  "active": true
}
Step 2

Read the encoded output

Encoding starts half a second after you stop typing. The bytes follow RFC 8949, using the shortest form for every integer, length and float.

•
Numbers keep their digits: whole numbers become CBOR integers at any length, so an ICCID like 8901240544102066246 is not rounded. Decimals become floats.
•
Keys keep their order: maps are written in the order the keys appear in your input.
•
Mistakes point to a line: broken JSON, YAML or XML shows the line and column where reading stopped, and nothing is encoded until it is fixed.
•
Size comparison: under the output you see the CBOR size next to the input size. Number-heavy data shrinks the most; long strings barely change.
•
Notes when something can't go across unchanged: for example a YAML 00501 kept as text, or a number too large for a float stored as text.

Example: the JSON above as CBOR (Base64)

o2RuYW1lZU1hZXZlY2FnZRgeZmFjdGl2ZfU=

That is 26 bytes, against 52 for the JSON with its indentation.

Step 3

Choose Base64 or Hex

CBOR is binary, so the page shows it as text you can copy. Switching between the two re-draws the same bytes.

•
Base64: four characters for every three bytes. Use it to put CBOR into a JSON field, an HTTP header, a database text column or a test fixture.
•
Hex: two characters per byte, easy to line up against the RFC when you want to see which byte is the map header and which is a length.
Step 4

Copy or download

•
Copy: puts the Base64 or Hex text on your clipboard, exactly as shown.
•
Download: saves encoded.cbor with the raw bytes, ready for a device, an MQTT payload or a CoAP test.
•
Check it: paste the Base64 into the CBOR Decoder or CBOR to JSON converter to see what a reader gets back.

Frequently Asked Questions

Which input formats can I encode?

Five: JSON, YAML, XML, CSV and plain text. Pick the tab that matches what you paste. YAML maps and lists become CBOR maps and arrays, and a file with several --- documents becomes one array. XML is read with element names as keys and text as strings (attributes go under _attributes, text under _text). A CSV becomes an array of maps, one per row, keyed by the header row. Plain text becomes a single CBOR text string, unless it is just a number, true, false or null.

What happens to long numbers like 8901240544102066246?

They are written as real CBOR integers with every digit, in JSON, YAML, CSV and plain text alike. Anything that fits 64 bits (up to 18446744073709551615, down to -9223372036854775808) uses the normal integer types, and anything bigger becomes a bignum (tag 2 or 3). Numbers with a decimal point or exponent, such as 14.50, become binary floats in the smallest width that holds them exactly, so they read back as 14.5. Text with leading zeros, like a 00501 zip code in a CSV or YAML file, stays text so the zeros are not lost.

How are CSV cells typed?

Only when nothing would change. A cell that is a plain number becomes a number, true and false (or TRUE and FALSE) become booleans, and an empty cell becomes null. Everything else, including 00501, 1,234 or a date, stays a text string exactly as it was written.

How do I read the CBOR back?

Download the .cbor file, or copy the Base64 or Hex text and turn it back into bytes, then hand it to any CBOR library: cbor2 in Python, cbor-x in JavaScript, fxamacker/cbor in Go, jackson-dataformat-cbor in Java or ciborium in Rust. To check the result without writing code, paste the Base64 into the CBOR to JSON converter on this site.

Is the output deterministic?

Every integer, length and float uses its shortest form and all lengths are definite, which is the preferred serialization in RFC 8949. Map keys stay in the order you wrote them instead of being sorted, so if you need the section 4.2 deterministic encoding for signing or hashing, sort the keys in your input first.

Is my data uploaded anywhere?

No. The encoding runs in your browser, so what you paste or upload is not sent to our server, and nothing is kept: a reload starts with an empty editor. Very large inputs are limited only by your device, though a file with tens of thousands of records can take a few seconds.