CODDY Tool

JSON Type Generator

Turn a JSON sample into type definitions for six languages.

Paste a JSON response and get TypeScript interfaces, Go structs, Kotlin data classes, Swift Codable structs, Python dataclasses or C# classes. Array elements are merged, so the result describes all your data rather than the first item.

Everything you enter stays in this browser tab. Nothing is sent to our servers, logged or stored.

Loading tool…

What JSON Type Generator supports

  • TypeScriptExported interfaces.
  • GoStructs with json tags.
  • KotlinData classes.
  • SwiftCodable structs.
  • PythonDataclasses.
  • C#Classes with properties.

About JSON Type Generator

Writing types by hand from an API response is tedious and error-prone, and the errors are the expensive kind: a field typed as required that is sometimes absent compiles perfectly and fails in production.

The difference between a usable generator and a toy is what it does with arrays. Reading only the first element of a list produces a type that describes that element and nothing else. This merges every element instead, so a field present in some objects and missing from others comes out optional, a field that is null in one place and a string in another comes out nullable, and an integer seen beside a decimal widens to a floating-point number.

JSON keys are also not identifiers. Keys like user-name, 2fa and class are all valid JSON and none of them can be a bare field name in most languages. Each language gets the treatment it actually uses — quoted keys in TypeScript, json tags in Go, @SerialName in Kotlin, CodingKeys in Swift, JsonPropertyName in C# — so the renamed field stays bound to the original key instead of silently reading nothing.

Nested objects become their own named types, named after the key that holds them, and a key holding an array is singularised so users produces a User. Types are emitted children first, which keeps the output compiling in languages that care about declaration order.

How to generate types from JSON

  1. Paste your JSON

    A full array beats a single object — the more samples, the more accurate the optional and nullable detection.

  2. Pick your language

    TypeScript, Go, Kotlin, Swift, Python or C#. Each uses that language's idioms rather than a translation of one template.

  3. Name the root type

    Nested types are named automatically from their keys.

  4. Copy or download

    The output is ready to paste into your project.

What the generator infers

  • Optional — a key missing from at least one object in an array.
  • Nullable — a key that is null in one sample and a real value in another.
  • Integer versus floating point — whole numbers stay integers until a decimal appears alongside them.
  • Nested types — each object gets its own named type, singularised when it came from an array.
  • Unknown — the same key holding genuinely different types, where no single type is honest.

What it cannot know

A sample is evidence, not a specification. A field that happens to be null in every example you paste is typed as null, because nothing in the data says otherwise. A string that is always a date stays a string. An enum with three values looks exactly like a string.

Treat the output as a fast, accurate first draft rather than a finished contract. If the API has a schema — OpenAPI, JSON Schema, protobuf — that is a better source of truth, and the generated types are the thing to check it against.

Frequently asked questions

Why is a field optional when my sample clearly has it?

Because another object in the same array did not. That is a genuine difference in your data, and marking it required would produce a type that compiles and then breaks on the object that lacks the field.

Why did a field come out as unknown or interface{}?

Because the same key held different types across your samples — a number in one object, a string in another. No single type describes both, so widening is the honest result. Fix it in the API, or narrow the type by hand once you know which is correct.

How does it handle keys that are not valid identifiers?

By renaming them and adding whatever mapping the language uses — json tags in Go, @SerialName in Kotlin, CodingKeys in Swift, JsonPropertyName in C#, and quoted keys in TypeScript. Without that, the renamed field would silently fail to read its value.

Is my JSON sent anywhere?

No. Parsing and generation both happen in this browser tab, so pasting a response from an unreleased API is safe.

All Developer Tools

JSON Type Generator is free to use with no account, no watermark and no usage limits. Last updated 14 August 2026.