Dumping Mapping topic

Dumps any Map-like objects.

Flow Mappings

Flow mappings start with { and terminate with }. All entries are always dumped on a new line. The default scalar style for flow mappings is ScalarStyle.doubleQuoted.

Implicit keys

Inline keys are dumped as implicit keys.

dumpMapping(
  { 'key': 'value' },
  collectionNodeStyle: NodeStyle.flow,
);
# Output in yaml
{
 "key": "value"
}

Explicit keys

Collections or multiline scalars are encoded with an explicit key.

dumpMapping(
  { {'key': 'value'} : {'key': 'value'} },
  collectionNodeStyle: NodeStyle.flow,
);
# Output in yaml
{
 ? {
  "key": "value"
 }: {
   "key": "value"
  }
}

Block Mappings

Block mapping have no explicit starting or terminating indicators. The default scalar style for block mappings is ScalarStyle.literal.

Explicit keys

Block mappings have a low threshold for explicit keys. Keys are encoded as explicit keys if:

  1. The keyScalarStyle is a block scalar style (literal or folded) or is null.
  2. The scalar is spans multiple line.
  3. The key is a collection (Map or Iterable).
dumpMapping(
  { 'key': 'value' },
  collectionNodeStyle: NodeStyle.block,
  keyScalarStyle: ScalarStyle.literal,
  valueScalarStyle: ScalarStyle.plain
);
# Output in yaml
? |-
  key
: value

Implicit keys

Only inline flow scalars are dumped as implicit keys.

dumpMapping(
  { 'key': 'value' },
  collectionNodeStyle: NodeStyle.block,
  keyScalarStyle: ScalarStyle.plain,
  valueScalarStyle: ScalarStyle.singleQuoted,
);
# Output in yaml
key: 'value'

Functions

dumpMapping<M extends Map>(M mapping, {int indent = 0, bool jsonCompatible = false, NodeStyle? collectionNodeStyle, ScalarStyle? keyScalarStyle, ScalarStyle? valueScalarStyle}) String Dumping Mapping
Dumps a mapping which must be a Mapping or Dart Map.