Skip to content
pubscout

checked_yaml

2.0.4, released a year ago by google.dev

Provides checkedYamlDecode to give detailed errors when decoding YAML with json_serializable.

WASM-readyQuiet but busy
$ flutter pub add checked_yaml
Source repository

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.

Works with

Packages commonly used together with checked_yaml: ones it builds on, ones built on it, and its own family.