JSON to TypeScript and Kotlin
Paste a sample JSON value and read TypeScript interfaces and Kotlin data classes. Nested objects, arrays and missing keys follow the sample.
- From a sample
- Free, no sign-up
Runs in your browser. Nothing you type or open is uploaded. Free to use, no account. More code and data tools
How to use it
- Paste a JSON object, array or value.
- Name the root type, and choose interface or type.
- Copy or download the TypeScript and the Kotlin.
What the sample decides
An object becomes an interface and a Kotlin data class. A nested object gets its own name from the key, and an array of objects uses the singular of that key. A key that is present on one object in an array and absent on another becomes optional. Null stays null in TypeScript and a nullable type in Kotlin. An empty array is unknown in TypeScript and Any in Kotlin, and a note says so.
Numbers that fit in a Kotlin Int are Int, larger whole numbers that fit in a Long are Long, and a number written in a way JavaScript keeps exactly stays a number or a Double. A whole number past that range is a string in TypeScript and a String in Kotlin, and the digits are kept. camelCase Kotlin names keep the original key on @SerialName when the spelling differs, and a Kotlin keyword is wrapped so it stays a legal name. A key that appears twice uses the later value. The types describe the sample. A date that is a string in the JSON stays a string.
Private by design
Privacy
Everything runs in this page and stays on your device. The sample you paste stays in this tab.
This page also shows Google ads, which can use cookies. Privacy and cookies explains how.
Questions
Does this write Kotlin as well as TypeScript?
Yes. The left box is TypeScript, as an interface or a type alias. The right box is Kotlin data classes, with kotlinx.serialization imports when the sample needs them.
What makes a field optional?
In an array of objects, a key that is missing from one of the objects becomes optional. A null value is included in the type.
How are big numbers written?
A whole number that fits in a Kotlin Int or Long uses that type. A number JavaScript cannot store exactly is a string in TypeScript and a String in Kotlin, and a note names the key.
What about a key like user_id or class?
With camelCase on, user_id becomes userId and keeps @SerialName("user_id"). The word class is a Kotlin keyword, so the property is written in backticks and keeps the original key.
From the same developer
- Catalog - UI: the matching app.


