[][src]Function pact_consumer::util::strip_null_fields

pub fn strip_null_fields<V>(json: V) -> Value where
    V: Into<Value>, 

Given a serde_json::Value, walk it recursively, removing any null fields, and return the updated value. Because of how this is normally called, it consumes its input value and returns the stripped value.

This function is most useful when serializing Rust types to JSON for use with each_like!, because it follows the pact convention of removing optional fields.

This example is not tested
use pact_consumer::prelude::*;

let actual = strip_null_fields(json!([
    null,
    { "a": 1, "b": null },
]));
let expected = json!([
    null,       // nulls in arrays are left alone.
    { "a": 1 }, // nulls in objects are stripped.
]);
assert_eq!(actual, expected);