Skip to main content

assert_json

Macro assert_json 

Source
macro_rules! assert_json {
    ($response:expr, $expected:tt) => { ... };
    ($response:expr, $expected:tt, $($msg:tt)+) => { ... };
}
Expand description

Asserts that a test response body matches the expected JSON value (partial match).

This macro performs partial JSON matching: the actual response may contain additional fields not present in expected, but all fields in expected must be present with matching values.

§Examples

use fastapi_core::assert_json;
use serde_json::json;

let response = client.get("/user/1").send();
// Response: {"id": 1, "name": "Alice", "email": "alice@example.com"}

// Exact match
assert_json!(response, {"id": 1, "name": "Alice", "email": "alice@example.com"});

// Partial match (ignores email field)
assert_json!(response, {"name": "Alice"});

With custom message:

assert_json!(response, {"status": "ok"}, "API should return success status");