YAML Input

Dart Output

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:

1

Paste or Upload Your YAML

Enter your YAML content in the left panel, or click Upload to load a .yaml or .yml file. Example:

user:
  name: Ava Chen
  age: 30
  active: true
2

Auto-Conversion

The converter instantly generates a Dart class with final fields, a named constructor, and a fromMap factory based on your YAML structure.

3

Copy or Download

Click Copy to copy the Dart code to your clipboard, or click Download to save it as a .dart file ready to add to your Flutter or Dart project.

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: