Dart to JSON Converter

Paste Dart classes or Flutter models. Get clean JSON back.

Input

Output

Paste your Dart code on the left and press Convert.

Or drop a file on this box, , or .

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

From a Flutter model to JSON in three steps, whether it is one class or your whole lib/models folder pasted together.

1

Paste your Dart (or try the sample)

Paste Dart into the left editor as it sits in your project: classes with final fields and required named parameters, a factory constructor that builds an instance, several classes at once. Load Sample loads an Order with a factory Order.sample(), a DateTime.parse timestamp and a Map<String, String> of metadata.

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 backend receives your Dart, works out what the constructor arguments would build and returns JSON for that instance, with a "Converting..." overlay showing until the reply lands.

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 toJson() will emit: helpful when designing a new model.

Keeping docs in sync

Produce the example responses for your package README or pub.dev page from the model classes themselves, so the documented JSON changes when the models do.

Common questions

Can I paste multiple classes at once?

Yes, an entire models.dart is fine. Each class at the top level gets a separate entry and nested instances are written out as nested objects. Underscore-prefixed private fields are included, which is also what a hand-written toJson() usually does.

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 goes to the backend for this conversion only and is not kept. Flutter projects often keep Firebase or API keys close to the models, so remove anything like that before pasting.

Other tools you may need

Flutter work rarely ends with one conversion: JSON to Dart covers the reverse trip, YAML to Dart handles config files, TypeScript types serve a web client, and the rest check the JSON you just made: