Skip to main content

from_json

Function from_json 

Source
pub fn from_json<'segments>(
    json: &str,
    builder: impl Into<Builder<'segments>>,
) -> Result<()>
Expand description

Decode a JSON string into a Cap’n Proto struct builder.

builder accepts anything that converts into a capnp::dynamic_value::Builder; it must be a struct builder, since JSON objects map to Cap’n Proto structs. The value mapping and annotations are the same as for to_json.

Fields absent from the JSON keep whatever builder already holds, and JSON fields with no counterpart in the schema are ignored.

Returns an error if json is malformed, if the top-level JSON value is not an object, or if any field’s value cannot be coerced to its declared Cap’n Proto type. On error, builder may have been partially populated.

This is Codec::new().decode(json, builder). Read the compatibility notes before decoding input you do not control.

capnp_json::from_json(&json, root)?;