Indent:
TypeScript Input 0 B
Ready
0 chars
JSON Output 0 B
JSON output will appear here...
0 chars
Features

Why use this converter

Strip annotations

Type annotations (: Type), type assertions (as Type), and const declarations are stripped, leaving pure JSON.

Quote handling

Single-quoted strings are converted to double-quoted to produce valid JSON. Embedded quotes are properly escaped.

Best-effort parse

The parser uses a regular expression to find the object literal, then evaluates it safely. Supports trailing commas and other JS-friendly syntax.

How it works

Conversion explained

1. Extract literal

The parser looks for = {...} pattern and extracts the object literal portion. If no assignment is found, it tries to parse the input directly as JSON.

2. Strip types

Type assertions (as Type) are removed with a regex. The remaining expression should be valid JavaScript.

3. Safe evaluation

The cleaned literal is evaluated via Function constructor with strict mode, returning a JavaScript value that is then JSON-stringified.

FAQ

TypeScript to JSON Converter — frequently asked questions

What TypeScript features are supported?

Object literals with strings, numbers, booleans, arrays, nested objects, null, and trailing commas. Type annotations, type assertions, and const/let/var declarations are stripped.

Why use this instead of tsc?

For simple cases (extracting a config object to JSON), this tool is much faster than running the full TypeScript compiler. It runs in your browser with no installation.

Is the evaluation safe?

The cleaned literal is evaluated via new Function() in strict mode with no access to your scope. It cannot access variables, execute arbitrary code beyond literal evaluation, or escape the sandbox.

Can I convert TypeScript interfaces to JSON Schema?

No — that's a different conversion. This tool extracts a value from a TS literal. For interface-to-Schema conversion, use a dedicated tool like typescript-json-schema.