JSON to TypeScript, Go, Java and Rust
FormattingEverything runs locally in your browser — nothing is uploaded
Paste a JSON sample and get type definitions you can drop into a project right away. This does more than echo key names back: a key that holds different types in different array elements is widened to a union (or to interface{}, Object and serde_json::Value in languages that have none), keys that only appear in some elements are marked optional, and nested objects with an identical shape share a single declaration instead of producing a wall of near-duplicates. Field names are converted to each language convention while the original key is preserved through json tags and serde rename attributes.
Features
- Four targets: TypeScript interfaces, Go structs, Java classes and Rust structs
- Keys missing from some array elements become optional: ? in TypeScript, pointers with omitempty in Go, Option in Rust
- Conflicting types at the same position widen to a union instead of silently picking one
- Nested objects with the same shape share one type; only genuine name clashes get a numeric suffix
- Field names follow each language convention: exported Go names with json tags, camelCase in Java, snake_case plus serde rename in Rust
- Unusual keys are handled per language: quoted in TypeScript, renamed with the original key kept for Go, Java and Rust
- Go struct tags fall back to a quoted form when a key contains a backtick, which would otherwise break the tag
- Only the root Java class is public, so the whole output can live in one file
- Nesting beyond 64 levels degrades to an any type instead of producing types nobody can read
- The root type name is configurable; anything that is not a valid identifier is normalised
How to use
- Paste a JSON sample that covers as many branches as possible
- Pick the target language
- Set the root type name and decide whether nullable fields should be optional
- Press Ctrl/⌘ + Enter or click Run, then copy the result
FAQ
- How accurate are the generated types?
- As accurate as your sample. When a key only ever holds one kind of value, the tool cannot tell a one-off from a rule, so include the awkward cases: null alongside a value, an integer alongside a decimal, and several array elements with different shapes. Loosening a generated type by hand is still much faster than writing it from scratch.
- Why do some fields get a question mark or a pointer?
- Because the key was missing from some array elements or was null in the sample. Turn the optional switch off and everything is emitted as required instead, which may no longer parse real responses.
- What happens to null values?
- In TypeScript the type is widened to include null, plus a ? when optional fields are enabled. Go uses a pointer, Rust an Option, and Java a boxed type such as Integer or Boolean.
- Is my JSON sent anywhere?
- No. Parsing, type inference and code generation all happen in your browser memory. The page makes no network requests and keeps working offline.
Related tools
JSON Formatter
FormattingFormat, minify and validate JSON, pinpointing syntax errors to an exact line and column. Optional key sorting; runs in your browser.
Mock Data
GeneratorsDescribe your fields once and get a batch of realistic mock records, exportable as JSON, CSV or a SQL INSERT. Everything is generated in your browser.
SQL Formatter
FormattingFormat SQL online: one clause per line, consistent keyword case, subqueries indented deeper. Minify strips comments and extra whitespace, all locally.
XML Formatter
FormattingFormat XML online by tag level, with comments, CDATA and DOCTYPE on their own lines and attribute values left untouched. Runs locally in your browser.
HTML Formatter
FormattingFormat HTML online by tag level, keeping text and inline tags on one line and script or pre content untouched. Runs locally, with nothing uploaded.
CSS Formatter
FormattingFormat CSS online: one declaration per line, selectors split at commas. Minify only strips structural whitespace, keeping meaningful spaces in values.