JSON to Type Definitions
Paste a JSON sample and get type declarations for six languages, instantly and entirely in your browser. Optional fields, nullability and nested types are inferred from the sample — and anything the sample cannot settle is reported rather than guessed.
Type definitions will appear here
The two things a sample cannot settle
Integers too large for a double
An ID above ±(2⁵³−1) gets int64 in Go, long in C#,
i64 in Rust — but TypeScript’s number physically cannot hold it, and
neither can a JSON parser in any JavaScript engine. We flag the field rather than emit a type that
quietly loses the last digits.
We measured which languages round it →
Fields with more than one type
If value is a number in one record and a string in the next, no correct type exists.
You get the language’s escape hatch — unknown, interface{},
Any, serde_json::Value — and a warning naming the field, so you can
narrow it by hand instead of discovering it at runtime.
What it infers correctly
A field missing from some objects in an array becomes optional. A field that is ever
null becomes nullable. Repeated object shapes are emitted once and reused. Keys that are
not valid identifiers — user-name, 2fa, class — are
renamed safely and mapped back with the right annotation for each language.
The output compiles
A generator is only useful if what it emits builds. The output for a deliberately awkward sample — containing a 64-bit ID, a null-only field, a mixed-type array, an empty array, a key with a space, a key starting with a digit, and keys that are reserved words in four of the six languages — is compiled on every change:
| Target | Checked with |
|---|---|
| TypeScript | tsc --strict |
| Go | go build, Go 1.22 |
| Python | imported under CPython 3.12 |
| Rust | cargo build with serde 1 |
| C# | dotnet build, .NET 8 |
| Java | javac, Java 21 + Jackson |
Worth being plain about the limit: types are inferred from one sample. If a field is absent from your sample it will be absent from the types, and if your sample happens to contain only integers in a field that can hold decimals you will get the wrong numeric type. Paste the widest sample you have. For a guarantee rather than an inference, start from a JSON Schema.
A page for each target
Each has its own examples and notes on how that language handles optional fields, nullability and large integers.