TypeScript to JSON Converter

Paste TypeScript interfaces or typed object literals. Get valid JSON back.

Input

Output

Paste your TypeScript code on the left and press Convert.

Or drop a file on this box, , or .

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 are resolved to their runtime values, so Status.Paid becomes whatever number or string the enum assigns to it. A new Date(...) is written as an ISO-8601 string, because RFC 8259 JSON has no date type. Properties set to undefined vanish and null stays null, the same way JSON.stringify treats them. Paste several interfaces and typed constants together and each constant gets a key of its own.

How to use it

Three steps. Works for a five-line interface or a whole types.ts module.

1

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.

2

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.

3

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 User interface and a sample instance to generate the example block for your OpenAPI schema in one shot.

Porting config to JSON

Moving from a typed config.ts 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. Interfaces, type aliases, enums and typed const declarations can all go in one paste. The types themselves produce no output; each const that holds a value gets a key, and the nested interfaces inside it are filled in from the literal.

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

Need interfaces generated from a JSON payload instead, or a validator for this one? Try these: