opyeb cborlab

cborlab · Conversion

What disappears between CBOR and JSON

The values silently lost when CBOR becomes JSON, and the points this tool warns about.

CBOR is not a superset of JSON. Both carry sets of values, but CBOR has several that JSON cannot express. When a converter quietly changes them, the data breaks quietly too.

Loss points

CBORIn JSONHow this tool handles it
non-integer map keykeys must be stringsconverted to a string with a warnJson.nonStringKey note
duplicate keythe last one winswarnJson.dupKey note
integer above 2^53lost precision as a doublewritten as a string with warnJson.bigInt
byte stringno matching typea {"$bytes":"base64url"} object
tagno matching typea {"$tag":n,"value":…} object
undefineddoes not exist{"$undefined":true}
simple valuedoes not exist{"$simple":n}
NaN or Infinitynot a JSON numberthe strings NaN and Infinity
indefinite lengthno such conceptsame value, the form is gone

Why the warnings sit beside the result

Copying only the JSON hides every loss above. This tool attaches the offset of each affected item so you can see where in the original bytes it happened.

Rules for going back

When encoding JSON to CBOR, {"$bytes":"…"} becomes a byte string, {"$tag":n,"value":…} a tag, and {"$map":[[key,value],…]} an integer-keyed map. With those rules most of the losses above can be reversed.

What to choose

The JSON view is for reference only and never replaces the original bytes. The .cbor file you download is the original.

Questions

Why base64url for byte strings?

It needs no escaping in URLs or JSON and has no padding, so it stays short.

Is not a string inconvenient for large integers?

It is, but it is correct. As a JSON number the value changes the moment it passes 2^53, so parsing the string straight into a big integer is safer.

Can every CBOR value be restored from JSON?

A tool that knows the $ rules above can restore most of them. The rules are not a standard, so agree them with the other side first.

Open the basic-map preset on the JSON tab to see how a byte string and a Float16 are shown and what is warned about.

Open the tool

Written against RFC 8949 (CBOR), RFC 9052 (COSE), RFC 8392 (CWT) and the IANA COSE algorithm registry. Every byte string and key here is synthetic.