Skip to main content

to_json

Function to_json 

Source
pub fn to_json<'reader>(reader: impl Into<Reader<'reader>>) -> Result<String>
Expand description

Encode a Cap’n Proto value as a JSON string.

reader accepts anything that converts into a capnp::dynamic_value::Reader — typically a struct reader obtained from message::Reader::get_root() or message::Builder::reborrow_as_reader().

Int64, UInt64, and non-finite floats are encoded as JSON strings, and Data fields are encoded as JSON arrays of bytes by default. The $Json.base64 and $Json.hex annotations override the Data encoding, and the $Json.name, $Json.flatten, and $Json.discriminator annotations affect the layout of object fields and unions, all matching the C++ capnp::JsonCodec behaviour.