do_json

Macro do_json 

Source
macro_rules! do_json {
    ($content:expr, $($key:ident = $val:expr),*) => { ... };
}
Expand description

§do_json!($content, $key1 = $val1, $key2 = $val2, …)

Macro Rules

The do_json macro takes a JSON string with placeholders and replaces them with provided values. It is an example of creating a specific macro wrapper for JSON content using do_replace!.

§Parameters

  • $content: The JSON string containing placeholders (e.g., "{\"name\": \"{{name}}\"}").
  • $key: The placeholder identifier (e.g., name).
  • $val: The value to replace the placeholder (e.g., "Ahmed").
// use cans::content::do_json;
use cans::do_json;

let json_content = r##"{"greeting": "{{greeting}}", "name": "{{name}}"}"##;
let json_result = do_json!(json_content, greeting = "Hi", name = "Ahmed");
assert_eq!(json_result, r##"{"greeting": "Hi", "name": "Ahmed"}"##);

End Doc