jsonValidator static method
jsonValidator to validate json
validator: (value) => SimpleValidations.jsonValidator(value, [errorMessage]),
Implementation
static String? jsonValidator(String? value, [String? errorMessage]) {
try {
if (value == null || value.isEmpty) {
return errorMessage ?? 'Required';
}
json.decode(value);
} catch (e) {
return errorMessage ?? 'Please enter a valid JSON';
}
return null;
}