checked_yaml
2.0.4, released a year ago by google.dev
Provides checkedYamlDecode to give detailed errors when decoding YAML with json_serializable.
What it does
Wraps json_serializable's generated fromJson to catch CheckedFromJsonException and rethrow as ParsedYamlException with source location. Works with yaml's YamlMap when anyMap:true is set.
AI-written summary of version 2.0.4, based on the package's README and metadata. Report an inaccuracy
Use it when
- You need precise error locations while parsing YAML into json_serializable models
- You already use json_serializable and yaml for config files
Skip it when
- You are not using json_serializable or yaml
- Performance‑critical parsing where extra exception handling is unwanted
Strengths
- Maps decoding errors to exact YAML line/column
- Seamlessly integrates with json_serializable's checked mode
- Supports latest Dart and yaml versions
Weaknesses
- Only works with json_serializable‑generated models
- Adds extra dependency and exception layer
- No benefit if you don't need detailed error reports
Setup
- Kind
- Pure Dart
- Effort
- Low
- Code generation
- Yes (build_runner)
- Direct dependencies
- 3
Add checked_yaml to pubspec; ensure json_serializable and build_runner are set up for code generation
void main(){
const yaml = '{"name": "", "count": 1}';
final config = checkedYamlDecode(
yaml,
(m) => Configuration.fromJson(m!),
);
print(config);
}Alternatives
Packages that do the same job and could replace checked_yaml.
- build
Package for authoring build_runner compatible code generators.
87Compare - carp_serializable
Polymorphic JSON (de)serialization using json_serializable with type info.
83Compare - dart_mappable
JSON serialization and data classes generator supporting generics, inheritance, and customization.
89Compare - copy_with_extension_gen
Generate type‑safe copyWith extensions for annotated classes and record typedefs.
85Compare
Works with
Packages commonly used together with checked_yaml: ones it builds on, ones built on it, and its own family.
- yamlchecked_yaml depends on itA Dart library for parsing YAML documents into Dart data structures.
- source_spanchecked_yaml depends on itStandard representation for source code locations, spans, and human-friendly error messages.
- json_annotationchecked_yaml depends on itProvides annotations for json_serializable to generate JSON (de)serialization code.
- json_serializableSame familyAutomatically generate code for converting Dart classes to and from JSON.
- skills_lintSame familyStatic analysis linter and CLI tool for Agent Skills (SKILL.md) structure and metadata
- neat_periodic_taskSame familyAuxiliary classes for reliably running periodic tasks in long-running processes.
- pubspec_parseBuilt on checked_yamlParse pubspec.yaml files with a type‑safe API and detailed error reporting.
- build_configBuilt on checked_yamlFormat definition and support for parsing build.yaml configuration.