jsonContains function
Used for comparing if a JSON object contains another JSON object.
Specifically, if json contains all the fields and values that are in jsonToContain.
E.g. if json is:
{
"name": "John",
"age": 30,
"address": {
"street": "Main Street",
"city": "New York"
}
}
and jsonToContain is:
{
"name": "John",
"address": {
"city": "New York"
}
}
Then json contains jsonToContain as all the fields and values in jsonToContain are in json.
listBehavior defines the behavior when comparing if a JSON list contains another JSON list.
By default when two lists are compared:
- lenght of the lists is not compared
- ordering of items is not compared
Implementation
bool jsonContains({
required Map<String, dynamic> json,
required Map<String, dynamic> jsonToContain,
JsonContainsListBehavior listBehavior = const JsonContainsListBehavior(),
bool debugLog = false,
}) {
try {
_throwIfNotAllWantedReceived(json, jsonToContain, listBehavior);
return true;
} catch (e) {
if (debugLog) {
log('json_contains: $e');
}
return false;
}
}