core/utils/safe_json library

Defensive Map-value parsers for JSON read from a not-fully-trusted source (an old save file, cloud data from a different app version, a hand-edited local file). Never throw — always fall back on a type mismatch or null instead of crashing the whole load over one bad field.

Functions

asBoolOr(Object? v, bool fallback) → bool
Reads v as a bool.
asDoubleOr(Object? v, double fallback) → double
Reads v as a double, accepting a JSON integer for it too (see asIntOr for why dart:convert can hand back either).
asIntOr(Object? v, int fallback) → int
Reads v as an int. dart:convert decodes a whole-number JSON value as int but a value with .0 may come back as double (or vice versa depending on the source) — both are accepted here.
asStringOr(Object? v, String fallback) → String
Reads v as a String (empty string is a valid value, not a miss).