← Back to DevKit

JSON to Type

JSON TO TYPE · GENERATORS

Infer JSON structure locally and generate type definitions for TypeScript, Go, Java and 9 languages total — int/float and nullable fields included.

JSON Input
Type definitions
Inference rules: integers and floats distinguished automatically (can force all-float); array elements merged recursively, mismatched same-name fields become unions; null fields marked nullable; duplicate type names get suffixes. Inferred fully locally — zero data upload.

>_ USAGE GUIDE

Paste a sample of an API's JSON response and the tool infers the structure locally, generating type definitions for nine languages including TypeScript, Go, Java, and Python in one click. The inference makes the distinctions that matter: integers versus floats (int vs float), nullable fields flagged (null becomes optional or pointer types), and array element types merged into one.

  1. Paste the sample JSON: any response body or fixture
  2. Pick the target language: TypeScript interfaces, Go structs with json tags, Java classes, and more
  3. Copy the generated types: drop them straight into your project — they compile as-is
  4. Review the nullable fields: confirm optionality against the API's real contract

Typical scenarios: onboarding a new API without hand-writing a screen of interfaces, converting a response structure into a Go struct ready for unmarshal, and typing test fixtures. A practical loop during development: paste the latest response, regenerate, and diff the types against the previous version — structural drift between deploys becomes visible in seconds. Inference and generation run entirely locally — API data is never uploaded.

>_ FAQ

Q1 · Why generate type definitions from JSON?

JSON is untyped: hard-coded field access relies on memory, and one typo surfaces only at runtime. Type definitions move the structure into code — editors autocomplete fields, renames are searchable across the project, and static checks catch errors before execution. Hand-writing them is tedious and error-prone, so paste-and-generate is the cheapest path from dynamic data to static safety.

Q2 · How accurate are the generated types — is it all guessing?

Inference is grounded in your sample: a 1 becomes an integer, "abc" a string, a null a nullable field. Accuracy depends on how representative the sample is — fields absent from the sample never appear in the types, and a field that is sometimes null but happened to be filled will be typed as required. Sound practice: generate first, then manually confirm the types and nullability of business-critical fields.

Q3 · What if array elements have inconsistent structures?

Element types are merged — fields are unioned and divergent ones marked optional — which is a reasonable approximation of the common "list with optional fields" shape. If the array mixes genuinely different objects, such as polymorphic responses, split the types by hand: the generator provides a starting point, not a finished contract.

Q4 · Which languages are supported, and what does the output look like?

TypeScript (interface/type), Go (struct with json tags), Java (class), Python (dataclass/TypedDict), and five more — nine in total. Each output follows its ecosystem's conventions: Go includes serialization tags, TypeScript preserves optional markers. Paste the result into your project and it compiles; adjust naming style to taste.

Q5 · Can I paste production API data?

Technically yes — generation is local with zero uploads. But following the minimum-exposure principle, mask first: replace real user data and tokens with fakes. Structure inference only cares about types, not values, so masking changes nothing in the output while removing any exposure risk.

Embed code

Paste the code below into your page to embed this tool as an iframe (nav and footer auto-hidden).

Heightpx
This tool runs entirely in your browser — input never leaves your device. Press Ctrl K to switch tools anytime.