Module value
The Value enum, a loosely typed way of representing any valid JSON value.
Constructing JSON
Serde JSON provides a json! macro to build serde_json::Value
objects with very natural JSON syntax.
use json;
The Value::to_string() function converts a serde_json::Value into a
String of JSON text.
One neat thing about the json! macro is that variables and expressions can
be interpolated directly into the JSON value as you are building it. Serde
will check at compile time that the value you are interpolating is able to
be represented as JSON.
# use json;
#
#
#
let full_name = "John Doe";
let age_last_year = 42;
// The type of `john` is `serde_json::Value`
let john = json!;
A string of JSON data can be parsed into a serde_json::Value by the
serde_json::from_str function. There is also
from_slice for parsing from a byte slice &[u8] and
from_reader for parsing from any io::Read like a File or
a TCP stream.
use ;
#
# untyped_example.unwrap;
Enums
- Value Represents any valid JSON value.
Functions
-
from_value
Interpret a
serde_json::Valueas an instance of typeT. -
to_value
Convert a
Tintoserde_json::Valuewhich is an enum that can represent any valid JSON data.