jsonDecodeSafe static method
Safely decodes a JSON string, returning null on error.
Implementation
@useResult
static dynamic jsonDecodeSafe(String? jsonString) {
final String? trimmed = jsonString?.trim();
if (trimmed == null || trimmed.isEmpty || trimmed == 'null') return null;
if (!isJson(trimmed)) return null;
try {
return dc.jsonDecode(trimmed);
} on FormatException catch (e, stackTrace) {
// debugPrint is appropriate for utility packages (stripped in release builds, no external dependencies)
// ignore: saropa_lints/avoid_print_error
debugPrint('JsonUtils.jsonDecodeSafe failed: $e\n$stackTrace');
return null;
}
}