json-matcher
Declarative JSON value matching for testing.
This library provides a flexible way to assert that JSON values match expected patterns, supporting both exact matching and flexible matchers for common types like UUIDs, dates, and arbitrary values.
Basic Usage
Use the [assert_jm!] macro to match JSON values against expected patterns:
use json;
use assert_jm;
let response = json!;
// Exact match using inline JSON syntax
assert_jm!;
Using Matchers
For flexible matching, use matcher types like [AnyMatcher], [UuidMatcher], or [U16Matcher]:
use json;
use ;
let response = json!;
assert_jm!;
Error Reporting
When assertions fail, [assert_jm!] reports all errors found (not just the first) and displays
the actual JSON value for debugging:
use json;
use ;
let response = json!;
// This will panic with a detailed error message showing:
// - All validation errors ($.id and $.name mismatches)
// - The full actual JSON value
assert_jm!;
// Output:
// Json matcher failed:
// - $.id: Expected valid UUID format
// - $.name: Expected string "Bob" but got "Alice"
//
// Actual:
// {
// "id": "not-a-uuid",
// "name": "Alice",
// "age": 25
// }
Custom Matchers
Create custom matchers by implementing the [JsonMatcher] trait:
use ;
use ;
;
let data = json!;
assert_jm!;
License: MIT