JsonParser class

Converts loosely-typed JSON-decoded values (num/String/List/Map/etc.) into strongly-typed Dart values, and detects a generic type parameter's runtime shape via the is T trick used throughout this class.

Constructors

JsonParser()

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 Methods

isDynamic<T extends Object?>() → bool
Whether T is dynamic/Object?.
isList<T extends Object?>() → bool
Whether T is List<dynamic>.
isListOfMapStringDynamic<T extends Object?>() → bool
Whether T is List<Map<String, dynamic>>.
isMap<T extends Object?>() → bool
Whether T is Map<dynamic, dynamic>.
isMapStringDynamic<T extends Object?>() → bool
Whether T is Map<String, dynamic>.
isString<T extends Object?>() → bool
Whether T is String.
valueAs<T extends Object?>(Object? value, {bool? allowHex, StringEncoding? encoding, bool asBytes = false}) → T
Central dispatcher: coerces value to whichever concrete type T is (num/String/List/Map/Set/etc.), by inspecting T's runtime shape.
valueAsBigInt<T extends BigInt?>(Object? value, {bool allowHex = false, bool? sign, bool allowDecimals = false}) → T
Coerces value (int/String/hex/decimal string) to a BigInt.
valueAsBool<T extends bool?>(Object? value) → T
Coerces value (bool or "true"/"false" string) to a bool.
valueAsBytes<T extends List<int>?>(Object? value, {bool allowHex = true, StringEncoding? encoding, bool allowJson = false}) → T
Coerces value to a byte list — accepts a raw byte List, a hex or encoding-decoded String, or (with allowJson) a JSON-encoded list/map.
valueAsDouble<T extends double?>(Object? value) → T
Coerces value (num/String) to a double.
valueAsInt<T extends int?>(Object? value, {bool allowHex = false, bool allowDouble = false}) → T
Coerces value (num/String/hex string) to an int.
valueAsList<T extends List?>(Object? value) → T
Coerces value to whichever concrete List<...> shape T is.
valueAsMap<T extends Map?>(Object? value) → T
Coerces value to a Map<String, dynamic> or Map<String, String>, matching whichever T actually is.
valueAsNum<T extends num?>(Object? value, {bool allowHex = false, bool allowDouble = false}) → T
Coerces value (num/String/hex string) to a num.
valueAsSet<T extends Set?>(Object? value) → T
Coerces value to whichever concrete Set<...> shape T is.
valueAsString<T extends String?>(Object? value, {bool allowJson = false, bool allowHexEncoding = false, StringEncoding? bytesEncoding = StringEncoding.utf8}) → T
Coerces value to a String — decodes byte lists, optionally JSON-encodes lists/maps.
valueEnsureAsList<T>(Object? value) → List<T>
Casts value to List<T>, converting each element if needed.
valueEnsureAsMap<KK, VV>(Object? value) → Map<KK, VV>
Casts value to Map<KK, VV>, rebuilding it if it isn't already one.
valueEnsureAsSet<T>(Object? value) → Set<T>
Casts value to Set<T>, rebuilding it if it isn't already one.
valueTo<T extends Object?, VV extends Object?>({required Object? value, required T parse(VV v), bool? allowHex, StringEncoding? encoding, bool asBytes = false}) → T
Coerces value to VV via valueAs, then applies parse to build a T.