1. Home
  2. Developer
  3. JSON to TypeScript, Kotlin & Dart

JSON to TypeScript, Kotlin & Dart

Paste a sample JSON response and get typed models for TypeScript, Kotlin or Dart.

Runs in your browser
Language
Style

Generated code

Waiting for input.

What is the JSON to TypeScript, Kotlin & Dart?

Writing model classes for an API response by hand is slow and error-prone. Paste a sample of the JSON and this tool generates ready-to-use types: TypeScript interfaces for web apps, Kotlin data classes for Android, and Dart classes with fromJson and toJson for Flutter.

Nested objects become their own classes, arrays of objects are merged so fields missing from some items become optional, numbers are typed as Int, Long or Double from the actual values, and JSON keys like first_name are mapped to idiomatic property names with the right annotation.

How to use it

  1. Paste a sample JSON response, or click Example.
  2. Choose the language, and for Kotlin the JSON library you use.
  3. Set the name of the root class.
  4. Copy the code into your project, or download it.

Example

Input
{"id": 7, "first_name": "Asha", "tags": ["pro"]}
Output
export interface Root {
  id: number;
  first_name: string;
  tags: string[];
}

Features

  • Three languages. TypeScript interfaces or types, Kotlin data classes and Dart (Flutter) classes.
  • Kotlin libraries. Annotations for kotlinx.serialization, Gson or Moshi.
  • Flutter-ready Dart. Null-safe classes with constructors, fromJson and toJson, no code generation needed.
  • Smart merging. All items of an array are combined; fields missing in some become optional.
  • Accurate numbers. Int, Long or Double chosen from the values in your sample.
  • Idiomatic names. first_name becomes firstName with the right @SerialName or JSON key mapping.

Frequently asked questions

How are optional fields detected?

From your sample. If a key is missing from some objects in an array, or its value is null, the property is made optional or nullable. Include a few varied items in your sample for the best result.

Which Kotlin library should I choose?

kotlinx.serialization is the modern default for Kotlin and Ktor. Choose Gson or Moshi if your Android project already uses Retrofit with those converters.

Do the Dart classes need build_runner?

No. fromJson and toJson are written out in full, so the classes work without json_serializable or any code generation.

Why is a field typed as Any or dynamic?

The sample had different types for that field (for example a number in one item and text in another), or only null, so a precise type could not be inferred. Adjust it by hand.

Is my JSON uploaded?

No. Code is generated in your browser.

Last updated · Free, no sign-up, runs in your browser.

Free for everyone, kept free by you.

No paywall, no sign-up and no watermarks. If a tool saved you time, you can chip in any amount by UPI to keep Nova Free Tools running.

Esc
↑↓ move↵ openEsc close