CBOR Encode
Convert JSON to its CBOR binary representation.
Encode JSON to CBOR (RFC 8949) as hex or Base64. Free, offline, runs in your browser. Read more Show less
What is CBOR?
CBOR (Concise Binary Object Representation) is a binary data format defined in RFC 8949. It encodes the same data model as JSON - numbers, strings, arrays, objects, booleans, null - but in a compact binary form that is faster to parse and smaller on the wire.
CBOR is used by COSE (the CBOR equivalent of JOSE, used in WebAuthn and FIDO2), by IoT protocols such as CoAP, by AT Protocol, and in many blockchain and DID systems. It is also the preferred binary encoding for structured data in constrained environments.
How to encode
Paste JSON into the input box. The tool parses it and emits the CBOR byte sequence as hex or Base64.
For example, the JSON {"a":1} encodes to:
a1616101 (hex)
That is 4 bytes: a1 (map with 1 pair), 61 (text string of length 1), 61 ("a"), 01 (integer 1). JSON would have used 7 bytes for the same data.
CBOR vs JSON
Same data model, different encoding. JSON is human-readable and universal. CBOR is smaller and faster. Use CBOR where bandwidth or parse time matters: mobile, embedded, and binary protocols. Use JSON where compatibility and readability matter: config files, REST APIs, logs.
CBOR supports more than JSON: integers of any size (bignum), byte strings (raw bytes, not Base64), indefinite-length items, tags, and simple values.
FAQ
Is the CBOR output deterministic?
For the same JSON input, this tool always produces the same bytes. The CBOR canonical form rules (sorting object keys, using shortest integer encoding) are applied by the underlying library.
Why is my JSON a different size after encoding?
CBOR stores integers, booleans, and null in 1 byte, short strings in 1+n bytes, and object keys without quotes. Small JSON payloads shrink substantially. Very large numbers or long strings of arbitrary bytes may grow.
Can I store binary data with CBOR?
Not with this tool - it accepts JSON, which has no byte-string type. To encode raw bytes as CBOR, use a library directly (for example cborg or cbor2).
What tags does this tool support?
None. Tags are a CBOR extension for typed values (dates, bignums, URIs). This tool handles the JSON-compatible subset only.
Command line equivalent
# Node with cborg
npm i cborg
node --input-type=module -e '
import { encode } from "cborg";
const bytes = encode({ a: 1 });
console.log(Buffer.from(bytes).toString("hex"));
'
# Python with cbor2
pip install cbor2
python3 -c "import cbor2, json; print(cbor2.dumps({'a':1}).hex())"
# Go with fxamacker/cbor
go get github.com/fxamacker/cbor/v2