pdata JSON/YAML/TOML for Dart

Typed Accessors

Part of the API Reference. The PdataTypedAccess extension on Map<String, dynamic> — available on whatever pdataReadFile or decodeJson/decodeYaml/decodeToml returns, no separate import needed. These give clear, actionable errors instead of a TypeError when a value is missing or the wrong shape.

final config = pdataReadFile('config.toml') as Map<String, dynamic>;
final port = config.getInt('port', defaultValue: 8080);
final debug = config.getBool('debug', defaultValue: false);
final name = config.getString('name'); // throws if missing

getInt

int getInt(String key, {int? defaultValue})

Returns the value for key as an int. Accepts a Dart int directly, a whole-number double, or a numeric String. Throws a FormatException if key is missing and no defaultValue is given, or if the value isn’t a valid int.

getDouble

double getDouble(String key, {double? defaultValue})

Returns the value for key as a double. Accepts any Dart num directly, or a numeric String. Throws a FormatException if key is missing and no defaultValue is given, or if the value isn’t a valid double.

getBool

bool getBool(String key, {bool? defaultValue})

Returns the value for key as a bool. Accepts a Dart bool directly, or (case-insensitively) the strings true/false, 1/0, yes/no, and on/off. Throws a FormatException if key is missing and no defaultValue is given, or if the value isn’t one of the above.

getString

String getString(String key, {String? defaultValue})

Returns the value for key as a String. Non-String values are converted via toString(). Throws a FormatException if key is missing and no defaultValue is given.

getList

List<dynamic> getList(String key, {List<dynamic>? defaultValue})

Returns the value for key as a List<dynamic>. Throws a FormatException if key is missing and no defaultValue is given, or if the value isn’t a List.

getMap

Map<String, dynamic> getMap(String key, {Map<String, dynamic>? defaultValue})

Returns the value for key as a Map<String, dynamic>. Throws a FormatException if key is missing and no defaultValue is given, or if the value isn’t a Map.