Function serde_json::to_vec_pretty

source ·
pub fn to_vec_pretty<T>(value: &T) -> Result<Vec<u8>>where
    T: ?Sized + Serialize,
Available on crate feature std only.
Expand description

Serialize the given data structure as a pretty-printed JSON byte vector.

Errors

Serialization can fail if T’s implementation of Serialize decides to fail, or if T contains a map with non-string keys.

Examples found in repository?
src/ser.rs (line 2162)
2158
2159
2160
2161
2162
2163
2164
2165
2166
2167
2168
pub fn to_string_pretty<T>(value: &T) -> Result<String>
where
    T: ?Sized + Serialize,
{
    let vec = tri!(to_vec_pretty(value));
    let string = unsafe {
        // We do not emit invalid UTF-8.
        String::from_utf8_unchecked(vec)
    };
    Ok(string)
}