Skip to main content

JSON to TypeScript

Typed models from a sample response.

Paste a representative API response and get TypeScript interfaces that describe it — or the equivalent models in Python, Java, Kotlin, Go, C#, Rust, PHP or JSDoc. The generator is deterministic: the same input always produces the same output.

Input JSON

Size: 0 BLines: 0

TypeScript models

Paste valid JSON to see the output.
Size: 0 BLines: 0

How type generation works

Jsonviewpro infers a shape for every value in the document and merges the shapes it finds. Crucially, the shapes of array items are merged with each other — a 10,000 element array of users produces one User type, not ten thousand.

Identical shapes are de-duplicated, so a nested address object that appears in three places yields a single Address type referenced three times.

Optional and nullable fields

  • A field present in some array items but not others becomes optional — email?: string in TypeScript, Option<String> in Rust, a nullable property elsewhere.
  • A field that is sometimes null becomes a nullable type — string | null.
  • A field with genuinely mixed types across records widens to the safest common type, and the analyzer flags it so you can decide whether the API is inconsistent.

Supported languages

TypeScript interfaces, JavaScript JSDoc typedefs, Python dataclasses, Java classes with getters and setters, Kotlin data classes with kotlinx.serialization annotations, Go structs with JSON tags, C# classes with System.Text.Json attributes, Rust structs with serde derives, and PHP typed classes.

Where a language convention renames fields — snake_case in Python and Rust, PascalCase in Go and C# — the generator emits the mapping annotation so serialization still matches the original JSON keys.

Use a real sample

Generated types are only as good as the sample. One record cannot tell the generator which fields are optional, and a truncated response cannot show which values are sometimes null. Paste the largest realistic response you have — ideally one that includes an empty state and an error case — and review the result before committing it.

For a contract you can validate against at runtime, generate a JSON Schema instead, or as well.

Frequently asked questions

Is this AI generated?
No. It is deterministic type inference. The same input always produces exactly the same output, and nothing is sent to a model or a server.
How are optional fields decided?
A field is optional when it appears in some, but not all, of the objects that share a shape — typically the items of an array.
Which languages are supported?
TypeScript, JavaScript (JSDoc), Python, Java, Kotlin, Go, C#, Rust and PHP.
Can I generate types from a huge array?
Yes. Array item shapes are merged as they are read, so output size depends on the variety of shapes, not on the number of records.