# JsonToCbor()

Converts a JSON string directly to CBOR (Concise Binary Object Representation) binary data. This is a shortcut when you already have JSON and want CBOR — it avoids the overhead of deserialising to CFML types first.

**Requires Extension:** [Crypto Extension](https://download.lucee.org/#17AB52DE-B300-A94B-E058FC978BE4542D)

```
JsonToCbor( json=string );
```

**Returns:** binary

# Arguments

| Argument | Type | Required | Description | Default |
|----------|------|----------|-------------|---------|
| json | string | Yes | JSON string to convert |  |

# Usage Notes

This converts directly from JSON to CBOR using the underlying library — it does not go through CFML types, avoiding the intermediate conversion step of `CborEncode( deserializeJSON( json ) )`.

**Key types:** JSON keys are always strings, so `JsonToCbor` produces CBOR text-string keys. If you need CBOR integer keys (e.g. for COSE), use [CborEncode()](cborencode.md) with a CFML struct instead — it converts numeric-looking string keys to CBOR integers automatically.

# Examples

```cfml
// Convert JSON directly to CBOR binary data

json = '{"name":"test","value":42}';
cbor = JsonToCbor( json );
// cbor is binary CBOR data

// Verify the roundtrip
backToJson = CborToJson( cbor );
parsed = deserializeJSON( backToJson );
// parsed.name == "test", parsed.value == 42

// Convert a JSON array
cbor = JsonToCbor( '[1,2,3,"four"]' );

// Encode existing API response data as CBOR for a system that expects it
apiResponse = '{"status":"ok","data":[1,2,3]}';
cborPayload = JsonToCbor( apiResponse );
// Send cborPayload to a CBOR-expecting endpoint
```







# Categories

[Cryptography](../../categories/crypto.md)

# See Also

[CborEncode()](cborencode.md), [CborToJson()](cbortojson.md)