tryJsonDecode static method

  1. @useResult
Map<String, dynamic>? tryJsonDecode(
  1. String? value, {
  2. bool shouldCleanInput = false,
})

Returns a decoded Map from the JSON string value, optionally cleaning the input first when shouldCleanInput is true, or null if decoding fails.

Implementation

@useResult
static Map<String, dynamic>? tryJsonDecode(
  String? value, {
  bool shouldCleanInput = false,
}) {
  if (value == null || value.isEmpty) return null;

  if (shouldCleanInput) {
    final String? cleaned = cleanJsonResponse(value);
    if (cleaned == null || cleaned.isEmpty) return null;

    return jsonDecodeToMap(cleaned);
  }

  return jsonDecodeToMap(value);
}