Function xpct::match_json

source ·
pub fn match_json<'a, Actual>(
    json: impl Into<Cow<'a, str>>
) -> Matcher<'a, Actual, Actual>where
    Actual: Debug + AsRef<str> + 'a,
Available on crate feature json only.
Expand description

Succeeds when the actual string and the expected string are equivalent JSON.

This allows you to compare JSON strings, ignoring whitespace and the order of keys in objects. The order of elements in arrays is still significant, though.

Examples

use xpct::{expect, match_json};

let expected = r#"
    {
        "name": "Reál",
        "code": "IIR"
    }
"#;

expect!(r#"{"code":"IIR","name":"Reál"}"#).to(match_json(expected));