TypeScript to JSON Converter
Paste TypeScript interfaces or typed object literals. Get valid JSON back.
What this tool does
You have a TypeScript interface plus a typed object literal, or a const config: Config = {...} assignment, and you need that value as real JSON — for an API request, a fixture, or an OpenAPI example. Paste the whole block here. The tool strips the type annotations, resolves the literal, and hands you JSON that parses anywhere.
Type-only syntax is handled the way the TypeScript compiler would handle it at emit time: interfaces and type aliases are erased, as const and satisfies don't change the output, Record<string, X> stays as an object, readonly and ? modifiers are ignored in the JSON (optional missing fields are simply absent). Strings quote the same way JSON.stringify does — double quotes, escaped where necessary — and keys are always strings.
Enums emit their runtime value. A numeric enum becomes a number, a string enum becomes a string. Date instances come out as ISO-8601 per RFC 8259. undefined properties drop out, null stays as null. Paste several interfaces and their instances in one go if you like — each instance ends up as a top-level entry in the JSON.
How to use it
Three steps. Works for a five-line interface or a whole <code>types.ts</code> module.
Paste your TypeScript (or try the sample)
Drop it into the left editor. An interface + typed object, a type alias, enum definitions, or exported const declarations — all fine. Click Load Sample to see what a realistic input looks like.
Leave the TypeScript handbook-style syntax alone — no need to strip generics, decorators, or import type statements. See the MDN JSON reference if you want a refresher on how JS-to-JSON mapping works.
Hit Convert
Click the green Convert button. The tool erases type info, evaluates literal values, and serializes them the same way JSON.stringify(obj, null, 2) would.
Copy the JSON
The right panel shows pretty-printed JSON ready to drop into a request body, an OpenAPI example, or a unit test fixture.
When this actually comes in handy
API request examples
You have an Angular, Next.js, or NestJS request DTO and need a JSON payload for Swagger, Postman, or a curl command. Paste the interface + object, get the JSON.
Unit test fixtures
Convert an inline typed mock used in a Jest or Vitest test into a standalone JSON fixture for MSW, Playwright, or integration runs.
OpenAPI and JSON Schema examples
Paste the <code>User</code> interface and a sample instance to generate the <code>example</code> block for your <a href="https://swagger.io/specification/" target="_blank" rel="noopener">OpenAPI</a> schema in one shot.
Porting config to JSON
Moving from a typed <code>config.ts</code> to a JSON-based config store? Paste the typed const, get clean JSON, drop it into your new config system.
Common questions
Does it strip type annotations and generics?
Yes. Interfaces, type aliases, generic parameters, as casts, satisfies, and readonly are all erased the same way the TypeScript compiler erases them. The JSON reflects only the runtime value.
How are enums handled?
Numeric enums emit the number, string enums emit the string. const enum is treated the same as a normal enum for the purposes of conversion. Enum references inside the object literal are resolved to their declared values.
What about optional fields and Record types?
Optional fields (name?: string) that are missing simply do not appear in the JSON — same as the default JSON.stringify behaviour. Record<string, X> stays as a JSON object keyed by the provided string keys.
Can I paste a whole types file?
Yes. Multiple interfaces, type aliases, enums, and typed const declarations can sit in one paste. Every top-level typed instance ends up as its own entry in the JSON, with nested types expanded in place.
How are Date, null, and undefined handled?
Date values become ISO-8601 strings. null stays as JSON null. undefined properties are dropped from objects. Arrays with undefined elements get null in that slot — matching JSON.stringify.
Is my code stored?
Code is sent to the backend only to be converted. It is not logged or persisted. If you are pasting anything sensitive, give it a look first.
Other tools you may need
TypeScript to JSON is one piece of the puzzle. Here are the tools that pair well with it: