Available on crate features
json and parse only.Expand description
serde JSON integration via the serde_json crate
Since serde derives requires linking with serde crate,
you have to add it to your Cargo.toml:
[dependencies]
serde = "1"use cu::pre::*; // with `serde` feature, Serialize and Deserialize are
// part of the prelude
#[derive(Debug, PartialEq, Serialize, Deserialize)]
struct FooBar {
foo: String,
}
// the json macro and json module will also be part of the prelude
let value1 = json!({"foo":"bar"});
let value2: FooBar = json::from_value(value1.clone())?;
assert_eq!(value2.foo, "bar");
let value3: FooBar = json::parse(r#"{ "foo": "bar" }"#)?;
assert_eq!(value2, value3);
Structs§
- Json
- JSON parse delegate. See
json - Map
- Represents a JSON key/value type.
- Number
- Represents a JSON number, whether integer or floating point.
Enums§
- Value
- Represents any valid JSON value.
Functions§
- co_read
coroutine - Parse value from an async reader that yields JSON
- from_
value - Convert a JSON value into T
- parse
- Parse value from a JSON
&str - read
- Parse value from a reader that yields JSON
- stringify
- Convert the value to a JSON string
- stringify_
pretty - Convert the value to a pretty-formatted JSON string
- to_
value - Convert a T into a JSON value
- write
- Serialize the value into JSON and write into the writer
- write_
pretty - Serialize the value into pretty-formatted JSON and write into the writer