Skip to content

std::encoding::json

Status: experimental

JSON parser, emitter, and derive support.

API details and source

The implementation source contains the complete declarations and implementation notes. The table below lists canonical Gossamer call signatures; every item name links directly to its implementation file.

Item Canonical signature or declaration Description
Deserialize trait Deserialize Trait for parsing a value from JSON.
Error type Error Error raised by encoding/decoding operations.
Serialize trait Serialize Trait for converting a value to JSON.
Value type Value Dynamically typed JSON value.
as_array fn as_array(value: json::Value) -> Option<Vec<json::Value>> Reads a dynamic Value as an array of Values.
as_bool fn as_bool(value: json::Value) -> Option<bool> Reads a dynamic Value as Option.
as_f64 fn as_f64(value: json::Value) -> Option<f64> Reads a dynamic Value as Option.
as_i64 fn as_i64(value: json::Value) -> Option<i64> Reads a dynamic Value as Option.
as_str fn as_str(value: json::Value) -> Option<String> Reads a dynamic Value as Option.
at fn at(value: json::Value, index: i64) -> Option<json::Value> Indexes an array element on a dynamic Value.
decode fn decode(source: String) -> Result<json::Value, errors::Error> Decodes a JSON String into a Deserialize value.
encode fn encode(value: json::Value) -> String Encodes a Serialize value as a JSON String.
encode_pretty fn encode_pretty(value: json::Value) -> String Renders a value as indented JSON text.
get fn get(value: json::Value, key: String) -> Option<json::Value> Looks up an object field on a dynamic Value.
is_null fn is_null(value: json::Value) -> bool Reports whether a dynamic Value is null.
keys fn keys(value: json::Value) -> Option<Vec<String>> Object field names of a dynamic Value.
len fn len(value: json::Value) -> i64 Element / field count of a dynamic Value.
parse fn parse(source: String) -> Result<json::Value, errors::Error> Parses JSON text into a dynamic Value.
render fn render(value: json::Value) -> String Renders a dynamic Value as compact JSON text.
set fn set(value: json::Value, key: String, next: json::Value) -> json::Value Sets an object field on a dynamic Value.
valid fn valid(source: String) -> bool Reports whether the text is well-formed JSON.