yamlMapToJsonMap function

Map<String, dynamic> yamlMapToJsonMap(
  1. YamlMap map, {
  2. Set<ToJsonObjectConverter> converters = const {},
})

Recursively converts map to a new map of type Map<String, dynamic>.

converters may be used to convert some specific objects to json representable objects. The first converter in the set that has a match with the type of the current value, as per ToJsonObjectConverter.isType will be used to convert the current value. There should only be one converter for each object type.

Implementation

Map<String, dynamic> yamlMapToJsonMap(
  YamlMap map, {
  Set<ToJsonObjectConverter<dynamic>> converters = const {},
}) {
  final newMap = <String, dynamic>{};

  for (final MapEntry(key: k, value: v) in map.entries) {
    if (k is! String)
      throw FormatException(
        "Each key in the YamlMap must be of type String, but there is one "
        "of type '${k.runtimeType}'.",
        map,
        k,
      );

    newMap[k] = _switchValue(v, converters);
  }

  return newMap;
}