json-rust icon indicating copy to clipboard operation
json-rust copied to clipboard

Display strings as quoted and escaped JSON string

Open dtolnay opened this issue 8 years ago • 0 comments

The Display behavior for strings is inconsistent with the behavior for other JsonValue variants. The others all display in JSON form.

#[macro_use]
extern crate json;

fn main() {
    println!("{}", json::JsonValue::Null);
    println!("{}", json::JsonValue::from(1.23));
    println!("{}", json::JsonValue::from(true));
    println!("{}", object!{ "code \n" => 200 });
    println!("{}", array![ "one", "two \n" ]);

    // :(
    println!("{}", json::JsonValue::from("str \n"));
}

dtolnay avatar Sep 03 '17 02:09 dtolnay