pdata JSON/YAML/TOML for Dart

String Codecs

Part of the API Reference. Work directly with format strings, with no filesystem involved — what the file functions call internally after reading/before writing.

PdataFormat

enum PdataFormat { json, yaml, toml }

The config-file formats pdata can read and write.

pdataDecode

dynamic pdataDecode(String source, PdataFormat format)

Decodes source as format into Dart objects. Dispatches to decodeJson, decodeYaml, or decodeToml below.

pdataEncode

String pdataEncode(dynamic data, PdataFormat format, {bool pretty = true})

Encodes data as format. pretty only affects JSON output; YAML and TOML are always written in a single, readable style. TOML documents must be a Map<String, dynamic> at the top level — a PdataFormatException is thrown otherwise, since TOML has no concept of a top-level scalar or list.

decodeJson / encodeJson

dynamic decodeJson(String source)
String encodeJson(dynamic data, {bool pretty = true, String indent = '  '})

A thin wrapper around dart:convert’s json codec. data must be composed of types JSON can represent: Map<String, dynamic> (with String keys), List<dynamic>, String, num, bool, and null. Throws Dart’s own FormatException on malformed input.

decodeYaml / encodeYaml

dynamic decodeYaml(String source)
String encodeYaml(dynamic data)

pdata’s own YAML parser and writer — see Supported Formats for exactly what’s accepted. Throws a PdataParseException on malformed input.

decodeToml / encodeToml

Map<String, dynamic> decodeToml(String source)
String encodeToml(Map<String, dynamic> data)

pdata’s own TOML parser and writer — see Supported Formats for exactly what’s accepted. Throws a PdataParseException on malformed input, or PdataFormatException if data contains a null value anywhere, since TOML has no null.