Skip to main content

6. Converting Data between CBOR and JSON

This section describes considerations for converting data between CBOR and JSON formats.

6.1. Converting from CBOR to JSON

When converting CBOR to JSON, certain CBOR features have no direct JSON equivalent:

  • Tags are not represented in JSON
  • Binary data must be encoded (e.g., as base64)
  • Maps with non-string keys require special handling
  • Integers outside JavaScript's safe range need attention

6.2. Converting from JSON to CBOR

Converting from JSON to CBOR is generally straightforward:

  • JSON objects become CBOR maps
  • JSON arrays become CBOR arrays
  • JSON strings become CBOR text strings
  • JSON numbers become CBOR integers or floating-point numbers
  • JSON booleans and null have direct CBOR equivalents