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.
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.
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.
You might also like
JSON to TypeScript
Generate TypeScript interfaces from JSON
JSON to Java
Generate Java POJO classes from JSON
JSON to Python
Generate Python dataclasses from JSON
JSON to Go
Generate Go structs from JSON
JSON Validator
Validate JSON syntax with detailed error messages
JSON Formatter
Format and beautify JSON with custom indentation