json-builder-macro 0.0.3

A lightweight macro for generating JSON objects
Documentation
  • Coverage
  • 54.55%
    6 out of 11 items documented2 out of 11 items with examples
  • Size
  • Source code size: 8.89 kB This is the summed size of all the files inside the crates.io package for this release.
  • Documentation size: 407.55 kB This is the summed size of all files generated by rustdoc for all configured targets
  • Ø build duration
  • this release: 9s Average build duration of successful builds.
  • all releases: 10s Average build duration of successful builds in releases after 2024-10-23.
  • Links
  • kaleidawave/experiments
    2 0 0
  • crates.io
  • Dependencies
  • Versions
  • Owners
  • kaleidawave

A simple macro for generating JSON

let object = json_builder_macro::json! {
    x: 78u32,
    y: 72.4f64,
    z: "thing"
};
assert_eq!(object, r#"{"x":78,"y":72.4,"z":"thing"}"#);

Also contains traits

let map = std::collections::HashMap::from_iter([("k1", "v1"), ("k2", "v2")]);
let out = &json_builder_macro::ToJSON::as_json_string(&map);
let valid = out == r#"{"k1":"v1","k2":"v2"}"# || out == r#"{"k2":"v2","k1":"v1"}"#;
assert!(valid);

and string JSON escaping

assert_eq!(&json_builder_macro::escape_json_string(r#"Hello "World""#), r#"Hello \"World\""#)