CborToJson()
Converts CBOR (Concise Binary Object Representation) binary data directly to a JSON string, without going through CFML types first. Useful when you receive CBOR from an external system and need to pass it on as JSON — for example, logging or forwarding WebAuthn attestation data to a JSON API.
Requires Extension: Crypto Extension
CborToJson( data=any );
Returns: String
| Argument | Description |
|---|---|
|
data
any,
required
|
edit
CBOR-encoded binary data |
Usage Notes
editThis converts directly from CBOR to JSON using the underlying library — it does not go through CFML types, avoiding the intermediate conversion step of serializeJSON( CborDecode( cbor ) ).
Binary data: CBOR byte strings are base64-encoded in the JSON output, since JSON has no native binary type.
Integer keys: CBOR integer keys (like those in COSE maps) are converted to JSON string keys, since JSON only supports string keys.
Examples
edit// Convert CBOR binary data directly to a JSON string
// A more direct alternative to serializeJSON( CborDecode( cbor ) )
cbor = CborEncode( { name: "test", value: 42 } );
json = CborToJson( cbor );
// json is a valid JSON string: {"name":"test","value":42}
// Convert a CBOR array to JSON
cbor = CborEncode( [ 1, "two", 3 ] );
json = CborToJson( cbor );
// [1,"two",3]
// Practical use: log WebAuthn attestation data as JSON for debugging
attestationCbor = Base64UrlDecode( response.attestationObject );
echo( CborToJson( attestationCbor ) );
See also
- Cryptography
- CborDecode()
- JsonToCbor()
- Search Issue Tracker open_in_new
- Search Lucee Test Cases open_in_new (good for further, detailed examples)