YAML to Dart Converter
Convert YAML to Dart class with final fields, constructor, and fromMap factory
YAML Input
Dart Output
Paste your YAML on the left and the Dart code shows up here.
Or drop a file on this box, , or .
What Is YAML to Dart Conversion?
YAML to Dart conversion transforms YAML (YAML Ain't Markup Language) data structures into Dart class definitions. Each top-level YAML key becomes a class with typed fields, a constructor, and a fromMap factory method for easy deserialization.
The converter maps YAML types to their Dart equivalents: strings become String, whole numbers become int, decimals become double (read through num, so a 9 in the data won't crash the cast), booleans become bool, and nulls become dynamic. Nested mappings get their own class with a fromMap factory, and lists of mappings become List of that class.
This tool is particularly useful for Flutter development where Dart data classes are commonly used to model API responses, configuration objects, and local data. For runtime YAML parsing, the yaml package on pub.dev handles the job. The generated code is compatible with manual serialization workflows.
How to Convert YAML to Dart
Follow these steps to generate a Dart class from your YAML data:
Paste or Upload Your YAML
Your YAML goes in the left pane, typed by hand or loaded with Upload (.yaml, .yml or .txt). Sample is a customer profile with an address, a tag list and an orders list, which gives you a few nested classes to look at. A four-line version:
user:
name: Ava Chen
age: 30
active: true Auto-Conversion
The converter generates a Dart class with final fields, a named constructor, and a fromMap factory based on your YAML structure.
Copy or Download
Copy puts the classes on the clipboard and Download saves them as root.dart. One catch if you read the file with package:yaml: loadYaml returns a YamlMap, which the generated as Map<String, dynamic> casts reject at runtime, so turn it into a plain map first (jsonDecode(jsonEncode(doc)) is the lazy way) before calling Root.fromMap.
Common Use Cases
Flutter Data Models
Generate Dart model classes from YAML API documentation or mock data for use in Flutter apps with clean, strongly-typed data objects.
Configuration Parsing
Convert YAML configuration files to Dart classes for use with Flutter's pubspec.yaml dependencies or custom config loading logic.
API Response Modeling
Transform YAML-documented API responses into Dart classes with fromMap factories, ready for integration with http or dio packages.
Code Generation Prototyping
Quickly prototype Dart data classes from YAML specs before wiring up full code generation tools like json_serializable or freezed.
Frequently Asked Questions
What Dart type does a YAML null become?
dynamic, because a null value on its own says nothing about the real type. If you know the field is, say, a nullable String, change it to String? by hand.
Are nested YAML objects supported?
Yes. Every nested mapping becomes its own class, and fromMap calls the nested class's fromMap for you, including for lists of mappings. Names are made valid Dart identifiers: first-name becomes firstName, 2fa becomes k2fa, and reserved words like class get a Value suffix, while the map key in fromMap stays the original.
Is the generated code compatible with json_serializable?
The generated code uses a manual fromMap pattern. To use json_serializable, you would add @JsonSerializable() annotations and run dart run build_runner build.
Can I use this for Flutter projects?
Yes. final fields with a fromMap factory are a common pattern for immutable Flutter models. Paste the classes into your project and run dart analyze; adjust nullability (String?) where your real data can be missing.
Does this tool work offline?
Yes. All YAML to Dart conversion is performed entirely in your browser using JavaScript. No data is sent to any server.
Related Tools
Explore these related YAML and Dart tools: