parseYamlToJson static method
Parses YAML content from a string and converts to JSON-compatible format.
Combines YAML parsing and JSON conversion in a single convenient method. This is the most commonly used method for processing AssetX configuration files from string content.
Parameters:
yamlContent: The raw YAML content as a string
Returns: A JSON-compatible Map<String, dynamic>
Process:
- Parses the YAML string using the yaml package
- Converts the result to JSON-compatible format
- Returns the processed Map ready for json_serializable
Example:
final yamlContent = '''
sources:
include:
- path: assets/
recursive: true
destination: generated
''';
final jsonMap = YamlUtils.parseYamlToJson(yamlContent);
final context = AssetXContext.fromJson(jsonMap);
Throws:
YamlException: If the YAML content is malformed- TypeError: If the root YAML structure is not a Map
Implementation
static Map<String, dynamic> parseYamlToJson(String yamlContent) {
final yamlMap = loadYaml(yamlContent) as Map<dynamic, dynamic>;
return convertYamlToJson(yamlMap);
}