pub fn try_assert_json_matches<Lhs, Rhs>(
lhs: &Lhs,
rhs: &Rhs,
config: &Config,
) -> Result<(), Vec<Difference>>Expand description
Compares two JSON values without panicking.
Returns a Result containing either Ok(()) if the values match,
or an Err with a Vec<Difference> describing the differences.
§Note:
This function performs some cloning and may be less efficient.
If you only need a string error message, use assert_json_matches_no_panic or the assertion
macros.
§Examples
use serde_json_assert::{try_assert_json_matches, Config, CompareMode};
use serde_json::json;
let lhs = json!({ "a": 1, "b": 2 });
let rhs = json!({ "a": 1 });
let config = Config::new(CompareMode::Inclusive);
let result = try_assert_json_matches(&lhs, &rhs, &config);
assert!(result.is_ok());
let lhs = json!({ "a": 1 });
let rhs = json!({ "a": 2 });
let config = Config::new(CompareMode::Strict);
let result = try_assert_json_matches(&lhs, &rhs, &config);
assert!(result.is_err());