DevTools Logo

JSON to TypeScript

JSON to TypeScript

Paste JSON and get clean TypeScript interfaces with inferred types

JSON Input

Paste a JSON object or array

Examples

Convert a flat object

Input
{"id":1,"name":"Ada","active":true}
Output
interface Root {
  id: number;
  name: string;
  active: boolean;
}

The object root becomes Root, and each observed primitive value determines its property type.

Convert an array root

Input
[{"id":1,"name":"Ada"}]
Output
type Root = RootItem[];

interface RootItem {
  id: number;
  name: string;
}

An array root becomes a Root type alias whose element object is named RootItem.

Preserve safe keys and quote other keys

Input
{"2024":12,"class":"release","display name":"Ada"}
Output
interface Root {
  "2024": number;
  class: string;
  "display name": string;
}

Numeric and spaced keys are quoted, while class matches the generator's identifier pattern and remains unquoted.

About this tool

JSON to TypeScript parses a JSON value with JSON.parse and generates TypeScript declarations from the values it observes. Object roots become interfaces, array and primitive roots become type aliases, nested objects become additional interfaces, and strings, numbers, booleans, and null map to their corresponding TypeScript types. Empty arrays become unknown[], while arrays containing different observed types become union arrays.

Interface names are derived from property names with a simple PascalCase conversion. Array property names are singularized with a small set of English suffix rules, and colliding interface names receive numeric suffixes. Property names that match a JavaScript identifier pattern are emitted directly; numeric, spaced, and punctuated names are quoted with JSON string syntax.

Choose a root interface name, paste an object, array, or scalar, and the declaration updates immediately. The generator infers only from the supplied sample: every object property is required, and it does not infer optional fields, literal types, dates, enums, or application-specific semantics.

How to use this tool

  1. Choose the root name

    Enter the name to use for the root declaration. Blank input falls back to Root, and punctuation or spaces in the name are removed by the PascalCase conversion.

  2. Paste valid JSON

    Paste a JSON object, array, or primitive into the input. Invalid JSON is reported with the message returned by JSON.parse.

  3. Review the inferred declarations

    Check primitive types, generated nested-interface names, array element unions, unknown[] results for empty arrays, and quoted property keys.

  4. Copy and refine the TypeScript

    Copy the generated output, then add optional markers, reusable domain types, literal unions, or other constraints that cannot be learned from one JSON sample.

Use cases

Typing an API response sample

Turn a captured JSON response into an initial set of interfaces before refining it against the API contract.

Scaffolding fixture types

Generate declarations from JSON fixtures used in tests, demos, or local development data.

Exploring unfamiliar payloads

Reveal nested object shapes and mixed array element types in a payload that is difficult to scan directly.

Starting a data-model migration

Create a first-pass TypeScript shape when moving a JSON-consuming script or JavaScript module to TypeScript.

Common mistakes

Mistake:Treating every generated property as known to be required across all real payloads.

Fix:The generator sees only one sample and emits every present property as required. Compare representative payloads or the source schema, then add ? to fields that may be absent.

Mistake:Assuming an array containing one object proves that the input is a single object or that every array item has the same shape.

Fix:Keep the generated array type when the JSON root or property is an array, and test multiple representative elements before trusting the inferred element interface.

Mistake:Removing quotes from numeric, spaced, or punctuated property names after generation.

Fix:Keep the emitted JSON-style quotes. Keys such as "2024" and "display name" do not match the generator's safe identifier pattern.

Mistake:Assuming a reserved word such as class must be renamed or that the generator will quote it.

Fix:Reserved words can be TypeScript property names, and this generator leaves any identifier-shaped key bare. Access or rename it according to your codebase conventions, not because it is a declaration error.

Frequently asked questions

What does it generate?

TypeScript declarations from a JSON sample. An object root becomes an interface, an array root becomes a type alias, nested objects become additional interfaces, and observed strings, numbers, booleans and null map to their corresponding TypeScript types.

Does it mark fields as optional?

No. The generator sees only the sample you paste, so every property present in that one sample is emitted as required. Compare representative payloads or the source schema, then add ? to fields that may be absent.

How does it handle arrays?

Empty arrays become unknown[]. Arrays whose observed elements have different types become a union type. Array property names are singularized with a small set of English suffix rules, so items becomes RootItem.

Is my JSON uploaded?

No. Parsing and declaration generation happen entirely in your browser — the JSON never leaves your device.

References & standards

.env Secret Safety Linter

Validate .env syntax and spot likely leaked credentials or placeholder secrets.

.htaccess Generator

Build an Apache .htaccess — HTTPS redirects, rewrites, error pages, security headers, and basic auth

2D Fluid Dynamics & Particle Physics Sandbox

A physics playground with two engines sharing one canvas. The fluid mode runs a real Eulerian Navier-Stokes solver — semi-Lagrangian advection, explicit diffusion, Jacobi pressure projection and vorticity confinement — that you paint with dye and velocity using mouse or touch. The particle mode is a damped Verlet N-body engine with gravity wells, Coulomb attractors and repulsors, spring links, wall restitution and elastic circle collisions. Particle counts adapt to the device (100k target on WebGL2 desktop, 2k-5k on CPU fallback), and every configuration exports as runnable code: a Matter.js world, a PixiJS ticker setup, or a standalone vanilla Canvas engine.

AI Function Calling Schema Generator

Generate function calling JSON schemas from TypeScript interfaces

Algorithm Arena & Data Structure Visualizer

Interactive arena for algorithms and data structures: eight sorting algorithms racing on one seeded input, six pathfinding algorithms walking generated mazes, and BST, AVL, Red-Black, B-tree, heap and trie operations replayed step by step with rotations highlighted. Every run shows the Big-O table and the phase-highlighted reference implementation in four languages, and compared values can be played as pitch (sonification) through the shared audio engine. Everything runs client-side; inputs never leave the browser.

Ansible Playbook Generator

Build an Ansible playbook — hosts, vars, and tasks with modules — as YAML