JSON to TypeScript, Java, Go & Python
Paste a JSON response and get ready-to-use type definitions. Nested objects become their own named types, and fields missing from some array items become optional.
JSON
TypeScript
How types are inferred
- Nested objects become separate types named after their key in PascalCase, so
"shippingAddress": {…}becomesShippingAddress. - Arrays of objects are merged: every item is inspected, and a field that's missing from some items is marked optional. Plural keys are singularised, so
"orderItems"becomes a list ofOrderItem. - Numbers become integers when every sample is a whole number, and floating point otherwise.
nullvalues make a field nullable. A field that's alwaysnullgets a catch-all type, because there's nothing to infer from.
What each language gets
- TypeScript: exported interfaces, with
?for optional fields and| nullfor nullable ones. - Java: records (Java 16+). Keys that aren't valid Java names get a Jackson
@JsonPropertyannotation. - Go: structs with
jsontags,omitemptyfor optional fields and pointers for nullable ones. - Python: dataclasses with type hints. Optional fields default to
None.
Check the result
The types are only as good as the sample. If your JSON has one item where an API usually returns many, some optional fields can look required. Paste a response with several items for the most accurate result.