[][src]Module serde_with::json::nested

Serialize value as string containing JSON

The same functionality is also available as serde_with::json::JsonString compatible with the serde_as-annotation.

Examples

#[derive(Deserialize, Serialize)]
struct A {
    #[serde(with = "serde_with::json::nested")]
    other_struct: B,
}
#[derive(Deserialize, Serialize)]
struct B {
    value: usize,
}

let v: A = serde_json::from_str(r#"{"other_struct":"{\"value\":5}"}"#).unwrap();
assert_eq!(5, v.other_struct.value);

let x = A {
    other_struct: B { value: 10 },
};
assert_eq!(r#"{"other_struct":"{\"value\":10}"}"#, serde_json::to_string(&x).unwrap());

Functions

deserialize

Deserialize value from a string which is valid JSON

serialize

Serialize value as string containing JSON