Skip to main content

to_string

Function to_string 

Source
pub fn to_string<T: ToJson + ?Sized>(value: &T) -> String
Expand description

Serializes value as compact JSON: no whitespace at all.

value is anything that implements ToJson: a Value, or your own type, written straight to text without building a Value. The output is deterministic: members in their order, numbers as their exact text, strings escaped as write_string describes. For a Value, parsing the output gives back an equal value.

ยงExamples

use jsonx_lib::{json, to_string};

let v = json!({ "id": 1, "tags": ["a", "b"], "none": null });
assert_eq!(to_string(&v), r#"{"id":1,"tags":["a","b"],"none":null}"#);
assert_eq!(to_string(&[Some(1), None]), "[1,null]");