Dump Map topic

Dumps any Map-like objects. The default scalar style is ScalarStyle.plain (you can override this).

Important

From version 0.3.1 and below in package:rookie_yaml, keys and values could have different scalar styles. This is no longer possible in package:dump_yaml. Both keys and values use the same scalar style.

You need to wrap the Map with a YamlMapping and implement a custom function that lazily converts the entries when toFormat is called if you relied on this functionality.

Flow Mappings

Flow mappings start with { and terminate with }. All entries are always dumped on a new line.

Implicit keys

Inline keys are dumped as implicit keys.

dumpAsYaml(
  {'key': 'value'},
  config: ConfiConfig.yaml(
    styling: TreeConfig.flow(
      forceInline: false,
      scalarStyle: ScalarStyle.doubleQuoted,
    ),
  ),
);
# Output in yaml
{"key": "value"}

Explicit keys

Collections or multiline scalars are encoded with an explicit key.

dumpAsYaml(
  {{'key': 'value'} : {'key': 'value'}},
  config: ConfiConfig.yaml(
    styling: TreeConfig.flow(
      forceInline: false,
      scalarStyle: ScalarStyle.doubleQuoted,
    ),
  ),
);
# Output in yaml
{{"key": "value"}: {"key": "value"}}

Inlined flow maps

You can always inline flow maps. This is quite handy since some flow nodes can act as implicit keys as long as they do not exceed the 1024 unicode-count-limit.

dumpAsYaml(
  {{'key': 'value'} : {'key': 'value'}},
  config: ConfiConfig.yaml(
    styling: TreeConfig.flow(
      forceInline: true,
    ),
  ),
);
# Output in yaml
{{key: value}: {key: value}}

Block Mappings

Block mapping have no explicit starting or terminating indicators.

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 spans multiple line.
  3. The key is a collection (Map or Iterable).
dumpAsYaml(
  {['block', 'list']: 'value' },
  config: ConfiConfig.yaml(
    styling: TreeConfig.block(),
  ),
);
# Output in yaml
? - block
  - list
: value

Classes

Alias Dump Scalar Dump List Dump Map Dumpable Views
An alias.
BlockDumper Dump Scalar Dump List Dump Map Dumpable Views Representation Tree
Dumps a YAML string line-by-line.
ConcreteNode<To> Dump Scalar Dump List Dump Map Dumpable Views
A node that is not an alias.
DumpableView Dump Scalar Dump List Dump Map Dumpable Views
An object that can be dumped to YAML.
InlinedFlowDumper Dump Scalar Dump List Dump Map Dumpable Views Representation Tree
Dumps an inlined flow CollectionNode.
TreeNode<T> Dump Map
A node representing a small or the entire chunk of a finalized YAML tree ready to be dumped.
YamlDumper Dump Scalar Dump List Dump Map Dumpable Views
A YAML document dumper.
YamlMapping Dump Map Dumpable Views
A mutable view for a Map-like object that can have YAML node properties.

Functions

dumpAsYaml(Object? object, {Config? config, ExpandObject? expand}) String Dump Scalar Dump List Dump Map Dumpable Views
Dumps an object to YAML using the config provided.

Typedefs

MapToYaml = ObjectFromView<YamlMappingEntry> Dump Map
Maps a map to a yaml mapping.
YamlMappingEntry = Iterable<MapEntry<Object?, Object?>> Dump Map
A list of MapEntrys for a YAML map.