Skip to main content

cbor_to_json

Function cbor_to_json 

Source
pub fn cbor_to_json(cbor: &[u8]) -> Result<Vec<u8>>
Expand description

Converts a CBOR document into its JSON encoding.

§Arguments

  • cbor - the CBOR document to convert.

§Returns

The UTF-8 JSON encoding of the same document, suitable for handing back to a runtime that reads JSON natively.

§Errors

Returns [Error::Codec] if cbor is not a valid CBOR document, or if it holds a construct with no JSON equivalent, such as a non-string map key.

§Examples

use pamoja_codec::{cbor_to_json, json_to_cbor};

let cbor = json_to_cbor(br#"{"c":21.5}"#).unwrap();
assert_eq!(cbor_to_json(&cbor).unwrap(), br#"{"c":21.5}"#);