Overview
Paste a JSON payload and read back an export interface that mirrors its shape — nested objects included, arrays typed, non-identifier keys quoted. Useful the moment an API response needs a type in a TypeScript codebase and you would rather not transcribe it by hand.
How It Works
Paste JSON into the editor, set the root type name (ApiResponse by default; anything outside letters, digits, and underscores is stripped from it), and the type is generated live. An object root produces an interface, anything else a type alias, and the Copy button takes the whole declaration.
Step-by-Step Usage Guide
- Paste the JSON payload — a sample response is preloaded.
- Set the root type name to what your codebase calls this payload.
- Read the generated interface; mixed arrays arrive as unions, empty ones as unknown[].
- Copy the declaration into your project.
Technical Specifications & Standards
The walker is hand-rolled rather than a library call: null maps to the literal type null, an empty array becomes unknown[], and an array whose elements differ in shape becomes a union such as (Admin | Guest)[]. Nested objects are inlined as anonymous object types rather than emitted as separate named interfaces, keys that are not valid identifiers are emitted quoted, and a cycle guard keyed on the serialized value stops repeated identical objects from recursing forever.
Targeted Use Cases
- Typing an API response before writing the fetch wrapper that consumes it.
- Turning a fixture file into the types a test harness expects.
- Sketching the shape of a config file that is currently just a JSON blob.
- Generating types for webhook payloads that are documented only by example.
Notes & Gotchas
- Fields absent in some samples but present in others do not become optional — merge several samples yourself and add the ? markers where the API is genuinely inconsistent.
- null becomes the literal type null, not a T | null union. If a field is meaningfully absent rather than null-typed, edit after copying.
- Nested objects are inlined, so deeply nested payloads produce one long interface. Extract named interfaces for anything you reference elsewhere.
- All numbers become number, and enum-like string values are not narrowed to literal unions — widen by hand where the domain needs it.
Frequently Asked Questions
Does it create a named interface per nested object?
No. Nested objects are inlined as anonymous types inside the root interface, which keeps the output copy-paste simple.
Why did my array become a union?
The elements have different shapes, so the generator unions each distinct element type, e.g. (Admin | Guest)[]. Uniform arrays collapse to a single Type[].
What happens to null fields?
They are typed as the literal null. The generator does not guess whether null means absent, so it never invents optional fields.
Is any of my JSON uploaded?
No. Parsing and generation run entirely in your browser.