Introduction topic
Despite the stick YAML gets, under all that complexity, is a highly configurable data format that you can bend to your will with the right tools. Based on the process model, the parser allows you to access data from the YAML string provided in two ways:
- As a built-in Dart type
- As a
YamlSourceNode.
Built-in Dart types
YAML supports various types out of the box which, by default, are built-in Dart types. These types include:
| YAML | Dart |
|---|---|
int (hex and octal are considered integers) |
int |
str |
String |
float |
double |
null |
null |
bool |
bool |
seq |
List |
omap, map |
Map (default maps behave like LinkedHashMaps) |
The parser deterimines these YAML types automatically as required by the spec. All tags, aliases, anchors and styles are stripped and objects returned as any of the Dart types mentioned above. The types are not wrapped in any intermediate class. Any unsupported scalar type will always be returned as a String.
YamlSourceNode
Alternatively, the parser can also emit a YamlSourceNode that:
- Is immutable.
- Has span information about the node in the source string or byte source.
- Persists its resolved/default tag assigned to it by the parser.
- Preserves its own anchor/alias information. Usually, every
AliasNodeholds a reference and anchor name to the actual node it referenced as an anchor. The same node also has the same anchor name. You need not worry about any node mismatch. - Preserves the integer radix for a
Scalarresolved asint.
It has 3 distinct subtypes that cannot be subclassed:
Mapping- corresponds to a DartMapSequence- corresponds to a DartListScalar- represents any type that is not a map or list.
Tip
Always select a loader for your YAML string based on the level of detail your require.
Additional Features
- A spec-compliant expressive API to declare tags and other YAML properties.
- Custom resolvers for custom tag shorthands.
CompactNodeinterface that allows custom objects to declare custom properties- Dumper functions that can dump any object to YAML.
Classes
- AliasNode Introduction Loading a YamlSourceNode Anchors and Aliases
- A node that is a pointer to another node.
- CompactYamlNode Introduction Loading a YamlSourceNode Dumping YAML Nodes
- A YamlNode with a set of node properties. This node is not necessarily limited to YAML's compact notation unless such a notation is required when the object is being dumped.
- Mapping Introduction Loading a YamlSourceNode
-
A read-only
YAMLMap which mirrors an actual Dart Map in equality but not shape. -
Scalar<
T> Introduction Loading a YamlSourceNode - Any value that is not a Sequence or Mapping.
- Sequence Introduction Loading a YamlSourceNode
-
A read-only
YAMLList which mirrors an actual Dart List in equality but not shape. - YamlNode Introduction Loading a YamlSourceNode
-
A simple node dumpable to a
YAMLsource string - YamlSourceNode Introduction Loading a YamlSourceNode
-
A node parsed from a
YAMLsource string.