JSON to Code
Turn JSON into model classes for Kotlin, Java, TypeScript, Dart, Swift, C#, Python, Go, Rust, PHP and Ruby.
Paste JSON on the left, or try the sample. The code appears as you type.
Need the data itself as YAML, XML or CSV? Use the Data Converter.
About JSON to Code
Paste a JSON response and get ready-to-use model classes: Kotlin data classes (plain, kotlinx.serialization, Moshi, Gson or Jackson), Java POJOs and records, TypeScript interfaces or types, Dart classes with fromJson and toJson, Swift Codable structs, C# classes, Python dataclasses and Pydantic models, Go and Rust structs, and PHP and Ruby classes. Every item of a list is checked, so keys that are missing from some items become optional and values that are sometimes null become nullable. Your JSON never leaves your browser.
How to use it
- Paste JSON, upload a .json file or try the sample.
- Pick the output in Convert to, for example Kotlin Serialization or TypeScript interface.
- Set the root class name and the options for the language, such as the JSON library.
- Copy the code or download it as a file.
Frequently asked questions
Is my JSON sent to a server?
No. The classes are worked out and written by your own browser. Nothing is uploaded.
How are the types chosen?
Text becomes a string, true and false a boolean, whole numbers an Int (or Long when they are too big), and numbers with a decimal point a Double. When a list mixes 1 and 2.5, the field becomes a Double. Values of different kinds, or a value that is only ever null, get a general type such as Any, Object or unknown.
Why are some fields nullable or optional?
If a key is null in the sample, or missing from some items of a list, real responses can leave it out too, so the code allows for it. Use a sample with several list items to get the most accurate result.
What happens to keys like user_name?
Kotlin and Java use camelCase names such as userName, with an annotation that keeps the original JSON key. TypeScript keeps the keys exactly as they are, because it reads the JSON directly.
Does the Dart code work with Flutter?
Yes. The default style writes fromJson and toJson by hand, so it needs no packages. Choose json_serializable to get the annotations for that code generator instead, then run build_runner.
Which library should I pick for Kotlin?
kotlinx.serialization is the usual choice for new Kotlin and Kotlin Multiplatform projects. Pick Moshi, Gson or Jackson to match a project that already uses one of them.