pdata JSON/YAML/TOML for Dart

String Codec

Part of the Examples. Decode a YAML string directly (no file involved), then re-encode the result as TOML and JSON.

Source: example/string_codec_example.dart

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

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

import 'package:pdata/pdata.dart';

const String yamlSource = '''
name: my-app
port: 8080
debug: false
tags:
  - cli
  - tool
author:
  name: psdk
  email: psdkjoon@gmail.com
''';

void main() {
  final data = decodeYaml(yamlSource) as Map<String, dynamic>;
  print('Parsed from YAML: $data');

  print('\nRe-encoded as TOML:\n${encodeToml(data)}');
  print('Re-encoded as JSON:\n${encodeJson(data)}');
}

Run it from the package root:

dart run example/string_codec_example.dart