What disappears between CBOR and JSON
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
| CBOR | In JSON | How this tool handles it |
|---|---|---|
| non-integer map key | keys must be strings | converted to a string with a warnJson.nonStringKey note |
| duplicate key | the last one wins | warnJson.dupKey note |
| integer above 2^53 | lost precision as a double | written as a string with warnJson.bigInt |
| byte string | no matching type | a {"$bytes":"base64url"} object |
| tag | no matching type | a {"$tag":n,"value":…} object |
| undefined | does not exist | {"$undefined":true} |
| simple value | does not exist | {"$simple":n} |
| NaN or Infinity | not a JSON number | the strings NaN and Infinity |
| indefinite length | no such concept | same 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
- JSON is convenient for exchange, but keep the Hex as well when byte strings, tags or large integers are present.
- Never convert signed bytes to JSON: one changed byte breaks the signature.
- For human reading, EDN loses less than JSON.
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.
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.