YAML to Dart
Paste any YAML document and instantly generate strongly-typed Dart classes with inferred field types.
Example
Input YAML:
name: Ada
age: 36
tags:
- dart
- flutter
Generated Dart:
class Root {
final String name;
final int age;
final List<String> tags;
Root({
required this.name,
required this.age,
required this.tags,
});
}How it works
It parses YAML with js-yaml, walks the resulting value to infer a type model (primitives, lists, and nested maps), then emits Dart classes with the root type named Root. Nested objects become their own classes named from their keys.
Good to know
YAML to Dart turns a sample YAML document into ready-to-paste Dart model classes, inferring a field type for every key so you don't have to write boilerplate by hand. It's aimed at Flutter and Dart developers who keep configuration, fixtures, or API responses in YAML and want a typed data layer that matches them. The whole conversion happens in your browser as you type, so nothing is uploaded and it keeps working offline once the page has loaded.
Reach for it when you're scaffolding models from an existing config file, prototyping against a YAML mock of an API, or migrating loosely-typed maps into named classes. The top-level object always becomes a class called Root, and each nested map becomes its own class named in PascalCase from its key. List item types are singularized when the tool builds a class for them, so a projects: list of maps yields a Project class rather than a Projects one.
To read the output, scan the inferred Dart types against your data: whole numbers become int, decimals become double, true/false become bool, and everything else string-like becomes String. Non-nullable fields are marked required in the generated constructor, while nulls produce nullable dynamic fields. A few edge cases are handled for you:
- A list mixing integers and decimals is widened to
List<double>, and a list with genuinely different types falls back to List<dynamic>. - A top-level list is wrapped in
Root with an items field, and a bare scalar is wrapped in Root.value.
One caveat: types are inferred only from the exact sample you paste, so a field that happens to be null or an empty list in your example will come out as dynamic or List<dynamic> even if it is really something more specific. Feed it a representative, fully-populated document for the cleanest result, then tighten any dynamic fields by hand. The tool also renames fields that collide with Dart keywords (appending an underscore) and converts keys to valid camelCase identifiers, so the generated code compiles without manual cleanup.
Frequently asked questions
How are nested YAML maps handled?
Each nested map becomes its own Dart class named from its key in PascalCase (for example an address map yields an Address class), and the parent holds a strongly-typed field referencing it.
What happens to null values or empty lists?
A null value becomes a nullable dynamic field, and an empty list becomes Listsince no element type can be inferred from the sample.
Is my data uploaded anywhere?
No — this tool runs entirely in your browser. Your input never leaves your device and it works offline once loaded.
Is it free?
Yes, completely free with no sign-up and no limits.
People also ask
Does YAML to Dart generate fromJson and toJson methods?
No. It generates the class definitions with typed fields and a constructor, but not serialization methods. You would add fromJson/toJson manually or pair the output with a code generator like json_serializable.
How does it convert YAML keys with hyphens or spaces into Dart field names?
Non-alphanumeric characters are stripped and the remaining parts are joined into camelCase, so a key like "first-name" becomes firstName. Keys starting with a digit get a leading character added so they form valid Dart identifiers.
What happens if a YAML key is a reserved Dart keyword like class or default?
The tool detects Dart reserved words and appends an underscore to the field name, turning default into default_, so the generated code still compiles.
Can it handle a YAML file whose top level is a list instead of a map?
Yes. A top-level list is wrapped in a Root class with a single items field whose type is inferred from the list elements.
How are numbers distinguished as int versus double?
Whole numbers are typed as int and numbers with a decimal point are typed as double. If a list contains both, the list is widened to List<double>.
Does the tool keep nullable types if a value is null in my sample?
A null value produces a nullable dynamic field, and that field is left out of the required constructor parameters. Because the type comes only from the sample, replace dynamic with a concrete nullable type if you know what it should be.
Is YAML to Dart the same as parsing YAML at runtime in a Flutter app?
No. This is a code-generation aid that produces class source you copy into your project. At runtime your app still needs a YAML or JSON parser to populate those classes.
Will it create duplicate class names if two nested maps share a key name?
It de-duplicates class names by appending a number when a generated PascalCase name already exists, so two different maps named config would become Config and Config2.
Related tools