JsonCare class

A tolerant JSON parsing helper designed to prevent runtime crashes caused by unexpected API type mismatches.

JsonCare provides static methods that safely cast or parse dynamic values into specific Dart types. If a value is null or cannot be parsed, it returns a sensible default value.

Constructors

JsonCare()

Properties

hashCode int
The hash code for this object.
no setterinherited
runtimeType Type
A representation of the runtime type of the object.
no setterinherited

Methods

noSuchMethod(Invocation invocation) → dynamic
Invoked when a nonexistent method or property is accessed.
inherited
toString() String
A string representation of this object.
inherited

Operators

operator ==(Object other) bool
The equality operator.
inherited

Static Properties

debug bool
Toggle debug logging for parsing mismatches.
getter/setter pair

Static Methods

boolVal(dynamic v, {bool def = false}) bool
Safely converts a dynamic value v to bool.
dateVal(dynamic v, {DateTime? def}) DateTime
Safely converts a dynamic value v to DateTime (Local Time).
doubleVal(dynamic v, {double def = 0.0}) double
Safely converts a dynamic value v to double.
enumValue<T>(dynamic v, List<T> values, {required T def}) → T
Safely converts a dynamic value v to an Enum value from the provided values list.
intVal(dynamic v, {int def = 0}) int
Safely converts a dynamic value v to int.
list<T>(dynamic v, T mapper(dynamic)) List<T>
Safely parses a dynamic value v as a List of items using a mapper function.
map(dynamic v) Map<String, dynamic>
Safely returns a dynamic value v as a Map<String, dynamic>.
string(dynamic v, {String def = ""}) String
Safely converts a dynamic value v to String.