Supported Formats
pdata is dependency-free: JSON goes through dart:convert, and YAML/TOML are read and written by pdata’s own parsers. Both cover the subset of their spec that the vast majority of hand-written config files actually use.
JSON
A thin wrapper around dart:convert’s json codec — full JSON support, since it ships with the Dart SDK itself. Malformed input throws Dart’s own FormatException, not a pdata-specific exception.
YAML
pdata implements its own single-document YAML parser (no package:yaml). Supported:
- Block mappings (
key: value) and block sequences (- item), nested through indentation. - Flow mappings (
{a: 1, b: 2}) and flow sequences ([1, 2, 3]), including nesting. - Single- and double-quoted scalars (with
\n,\t,\r,\",\\, and\uXXXXescapes in double-quoted strings;''for a literal quote in single-quoted strings) and plain unquoted scalars. null/~/empty,true/false, integers, and floats.- Comments (
#to end of line, outside of quotes). - Literal (
|) and folded (>) block scalars, including the-/+chomping indicators.
Not supported: multiple documents in one string, anchors/aliases, tags, and explicit block-scalar indentation indicators (e.g. |2).
encodeYaml always writes block style (never flow), with two-space indentation — regardless of which style the source used, if any.
TOML
pdata implements its own TOML parser (no package:toml), covering the TOML v1.0 features used by the vast majority of hand-written config files:
- Key/value pairs with bare, quoted, and dotted keys.
[table]headers, nested via dotted names, and[[array.of.tables]].- Inline tables (
{ a = 1, b = 2 }) and arrays ([1, 2, 3], including multi-line arrays with trailing commas). - Basic (
"...") and literal ('...') strings, including their triple-quoted multi-line forms. - Integers (decimal,
0x,0o,0b, with_separators), floats (includinginf/nan), booleans, and RFC 3339 date-times (parsed intoDateTimewhere possible; kept as text otherwise). - Comments (
#to end of line, outside of strings).
TOML has no top-level scalar or list, so decodeToml always returns a Map<String, dynamic>, and encodeToml requires one as input — a PdataFormatException is thrown otherwise. TOML also has no null; encoding a map containing one throws the same exception. Omit the key instead of setting it to null.