Paste Dart on the left and click "Convert" — we will turn it into JSONPaste Dart code

What this tool does

If you are building a Flutter app and you have a model class with a toJson() you have not written yet, or you just need a sample JSON body for a test, hand-crafting the map is tedious. Paste your Dart here and you get back valid JSON — no boilerplate, no rewriting. Works with a single class, a full models.dart file, or an instance you have constructed with named arguments.

The converter follows how dart:convert actually serializes. final fields come through with their values. int and double stay as JSON numbers. bool stays a boolean. DateTime becomes an ISO-8601 string, the same format DateTime.toIso8601String() produces. List<T> becomes a JSON array; Map<String, dynamic> becomes a JSON object. Nullable types (String?) emit null when the value is null, or the value itself otherwise.

Factory constructors, named constructors, and fromJson/toJson helpers are all recognised — the data inside an instance is what ends up in the output. If you paste multiple classes from a single file (say, pulled from a pub.dev package), each class becomes a top-level entry with nested instances expanded as nested JSON objects. Methods are skipped. Enums serialize to their name by default, matching the common describeEnum convention.

How to use it

Three steps. Same flow whether you paste a small class or a whole models.dart.

1

Paste your Dart (or try the sample)

Drop your Dart code into the left editor as-is. A class definition, a factory constructor, multiple classes, or an instance with named args — all fine. Click Load Sample to see a realistic example.

Keep imports, annotations (@JsonSerializable(), @freezed), and comments — the parser ignores what it does not need. For deeper context on the language, dart.dev/language is the canonical reference.

2

Hit Convert

Click the green Convert button. The tool reads the Dart, walks every class and field, and produces JSON in one pass. A short loading indicator shows while it runs.

3

Copy the JSON

The right panel fills with indented JSON. Drop it into a Flutter test, a mock response for Dio/http, a Firestore seed, or your API docs.

When this actually comes in handy

Flutter integration tests

You have an Order model with nested Customer and OrderItems. Paste the class, get the JSON, use it as a mock response in your integration test.

API payload bootstrapping

Turn a CreateOrderRequest class into a JSON body ready for Postman, curl, or a quick backend spike — no more typing it by hand.

Bootstrapping json_serializable

Before running build_runner, you can see exactly what shape <code>toJson()</code> will emit — helpful when designing a new model.

Keeping docs in sync

Generate JSON samples for a README or API reference straight from your Dart models so documentation tracks the actual code.

Common questions

Can I paste multiple classes at once?

Yes — paste an entire models file. Each top-level class becomes its own JSON entry, and nested instances are expanded as nested objects. Private fields (underscore-prefixed) are still emitted, same as what a toJson() would usually produce.

How does it handle DateTime, Duration, and nullables?

DateTime comes out as an ISO-8601 string per toIso8601String(). Duration is a numeric microsecond count. Nullable fields (String?) emit null when the value is null, or the value itself otherwise.

What about List, Map, and Set?

List<T> and Set<T> both become JSON arrays — JSON has no set type, so the members are listed. Map<String, dynamic> becomes a JSON object. Nested generics (List<Map<String, Order>>) are expanded recursively.

Does it understand freezed or json_serializable classes?

Yes — the @freezed and @JsonSerializable annotations are recognised and the underlying fields are pulled into the JSON. You do not need to run build_runner first; the converter reads the declaration, not the generated code.

How are enums emitted?

By default, the enum value name is used (OrderStatus.paid"paid"). That matches the common convention and keeps the JSON human-readable without needing extra mapping code.

Is my code stored?

Your Dart is sent to the backend for conversion and is not persisted — we do not log the payload. For sensitive model code, scrub or review before pasting.

Other tools you may need

Dart to JSON is one piece. These pair well with it: