isDeepValid static method
Deeply validate the given json.
json is considered valid iff it contains a primitive value (of
type Null, bool, int, double, String) or a composite
value (of type List<dynamic> or Map<String, dynamic>) whose
elements (of the list) or values (of the map) satisfy the same
constraints recursively.
Implementation
static bool isDeepValid(Json json) {
var v = json.value;
if (v == null || v is bool || v is num || v is String) {
return true;
}
if (v is List<Json>) {
for (Json json in v) {
if (!isDeepValid(json)) return false;
}
return true;
}
if (v is Map<String, Json>) {
for (Json json in v.values) {
if (!isDeepValid(json)) return false;
}
return true;
}
// Some other type, can't be a Json.
return false;
}