JSON to TypeScript
Generate interfaces or types with optional-field controls from JSON.
Runs in your browser. Nothing is uploaded.
Infer types from a JSON example
JSON to TypeScript reads a JSON value and creates TypeScript declarations that describe its shape. An object becomes an interface or type, primitive values become TypeScript primitives, and nested objects become named declarations. The result is a useful starting point when an API response or fixture exists before a hand-written type does.
Paste an object, use the sample, or drop a JSON file into the input area. The page parses JSON first, so malformed syntax is reported before inference. The sample produces an interface that includes a name property, and the output can be copied or downloaded as types.ts. Use JSON Formatter when you need to inspect the source independently.
What the generated declarations mean
An inferred declaration describes the values visible in the example, not every response your service might return. A property present in one fixture may be optional in production. A string may actually be a date, identifier, or constrained union. A number may represent a count, currency, timestamp, or another unit that the generator cannot know from JSON alone.
Arrays deserve the same review. A homogeneous list can produce a simple item type, while mixed items may need a union or a manually designed discriminated type. If null appears in a sample, check whether the field is nullable, optional, or both in the real contract.
Use the output as a starting point
After copying the declarations into a project, rename the root and nested types to match your domain. Add optional markers, literal unions, branded identifiers, documentation, and validation at the boundary where untrusted data enters your application. TypeScript declarations alone do not validate runtime JSON.
Compare a second representative response when the API has multiple shapes. The more complete the sample set, the less manual correction the generated output needs. For related structured data work, JSON to YAML and JSON to XML convert the same parsed kind of input for different receiving systems.
Local processing and review
Parsing, type inference, file reading, and downloading happen in your browser. Nothing is uploaded. Inspect the generated declarations before committing them, especially when the input includes private fields or values that should not appear in source control. The tool is an inference aid, not a schema registry or a substitute for runtime validation.
FAQ
Does JSON to TypeScript send my sample anywhere?
The JSON is parsed and passed to the TypeScript inference engine in your browser. The sample is never uploaded, and TheDevTab never receives it.
What JSON shape should I provide?
Provide a representative JSON object or array with the keys, values, and nested structures you expect. The engine uses that sample to infer interface or type declarations, but it cannot infer fields that the sample does not contain.
Does the output validate my API schema?
No. The generated declarations describe the example you supplied and do not validate future API responses. Add runtime validation if the application must reject data that does not match the expected shape.
How are arrays handled?
Arrays of objects merge their keys and make keys missing from some objects optional, while scalar arrays become arrays of the inferred union. An empty array becomes unknown[], and a mixed or nested shape may still need manual review.
What about null values?
Null is emitted as the null type and joins other observed types in a union such as string | null. Null does not by itself make a property optional, while a key missing from some object samples does.
Can I choose interfaces or type aliases?
Yes. The Use type instead of interface option switches each declaration between an exported type alias and an exported interface. All properties optional adds ? to inferred fields, and Root name changes the root declaration name.