pdata 1.0.0 copy "pdata: ^1.0.0" to clipboard
pdata: ^1.0.0 copied to clipboard

A reader/writer for JSON, YAML, and TOML config files, in pure Dart.

example/pdata_example.dart

// Run this example from the package root:
//   dart run example/pdata_example.dart

// print() is fine in example scripts; avoid it in production code instead.
// ignore_for_file: avoid_print

import 'package:pdata/pdata.dart';

void main() {
  final config = <String, dynamic>{
    'name': 'my-app',
    'version': '1.0.0',
    'debug': false,
    'port': 8080,
    'tags': ['cli', 'tool'],
    'author': {'name': 'psdk', 'email': 'psdk@example.com'},
  };

  // Write the same data out as JSON, YAML, and TOML.
  pdataWriteFile('build/config.json', config);
  pdataWriteFile('build/config.yaml', config);
  pdataWriteFile('build/config.toml', config);

  // Format is guessed from the extension, so reading is symmetric.
  final fromYaml = pdataReadFile('build/config.yaml') as Map<String, dynamic>;
  print('Loaded from YAML:');
  print('  name: ${fromYaml.getString('name')}');
  print('  port: ${fromYaml.getInt('port')}');
  print('  debug: ${fromYaml.getBool('debug')}');
  print('  tags: ${fromYaml.getList('tags')}');

  // Typed accessors give a clear error (instead of a crash) for a missing
  // key, unless you supply a default.
  final timeout = fromYaml.getInt('timeout', defaultValue: 30);
  print('  timeout (default): $timeout');
}
0
likes
160
points
39
downloads

Documentation

API reference

Publisher

unverified uploader

Weekly Downloads

A reader/writer for JSON, YAML, and TOML config files, in pure Dart.

Repository (GitHub)
View/report issues

Topics

#json #yaml #toml

License

MIT (license)

More

Packages that depend on pdata