#[derive(DisplayAsJsonPretty)]
Expand description

Implements Display as a wrapper around serde_json::to_string_pretty.

See this crate’s documentation for more examples on how you can use this custom derive procedural macro.

Example:

use serde::Serialize;
use display_json::DisplayAsJsonPretty;

#[derive(Serialize, DisplayAsJsonPretty)]
#[serde(tag = "type")]
#[serde(content = "val")]
#[serde(rename_all = "lowercase")]
enum EitherStringOrNum {
  String(String),
  Num(f64),
}

let res = r#"{
  "type": "num",
  "val": 12.0
}"#;

let num = EitherStringOrNum::Num(12.);
assert_eq!(num.to_string(), res);

let res = r#"{
  "type": "string",
  "val": "hello"
}"#;

let string = EitherStringOrNum::String("hello".to_owned());
assert_eq!(string.to_string(), res);