About JSON to Code
JSON to Code saves you from typing out model classes by hand when you start on a new API. Paste a sample response from the API documentation or your browser's network tab, pick a language, and you get TypeScript interfaces, Java classes, Go structs with json tags, Python dataclasses, C# classes with JsonPropertyName attributes, PHP classes with typed properties, Kotlin data classes or Swift Codable structs. If the API is public and you have no sample yet, the HTTP Request Tester can fetch one.
Nested objects become their own named types, and the objects in an array are merged, so a field that appears in only some items is marked optional. You can set the name of the root type. Treat the result as a starting point: a single sample can't show every case, so check types and names against the API documentation. If the sample won't parse, find the problem first with the JSON Formatter. It all runs in your browser, so responses with real data never leave your device.
How to use JSON to Code
- 1Paste a JSON sample
Paste an API response or open a .json file.
- 2Pick a language
Choose TypeScript, Java, Go, Python, C#, PHP, Kotlin or Swift.
- 3Name the root type
Set the name of the top-level class, struct or interface.
- 4Copy the code
Copy the generated types or download them.
Why use Cubfile for this
- Eight languages
TypeScript, Java, Go, Python, C#, PHP, Kotlin and Swift.
- Nested types
Every nested object becomes its own named type.
- Optional fields
Objects in arrays are merged, and fields missing from some of them are marked optional.
- Annotations included
Go json tags, C# JsonPropertyName attributes and Swift Codable come ready.