value

Macro value 

Source
macro_rules! value {
    ($matcher:expr) => { ... };
}
๐Ÿ‘ŽDeprecated since 0.2.0: please use json::primitive! instead
Expand description

Matches a JSON value (string, number, or boolean) against the given matcher.

This macro enables matching specific primitive values inside a JSON structure by delegating to a matcher for the corresponding Rust type. It supports:

  • String values (e.g. json::value!(eq("hello")))
  • Number values as i64 or f64 (e.g. json::value!(ge(0)))
  • Boolean values (e.g. json::value!(eq(true)))

Fails if the value is not of the expected JSON type.

ยงExample

let data = j!({"active": true, "count": 3});

verify_that!(data["active"], json::value!(eq(true)));
verify_that!(data["count"], json::value!(ge(0)));