jsonValidator static method

String? jsonValidator(
  1. String? value, [
  2. String? errorMessage
])

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;
}