Mock data · Serialization · JSON Schema — 3 modes

Convert TypeScript
to JSON. Three ways,
one tool.

Generate mock JSON from an interface, get typed JSON.stringify() snippets, or convert your interface to a JSON Schema. Choose the mode that matches your use case.

Your data never leaves your browser
Mock JSON from interface
Typed stringify() snippets
Interface → JSON Schema
Always free
TypeScript to JSON — 3 modes   100% client-side
TypeScript interface
  Result ready

      
Three ways to convert TypeScript to JSON

Each mode covers a different intent — choose the one that fits your use case.

Mode 1 — Mock JSON from interface

Paste a TypeScript interface and get a valid JSON object with realistic example values. Useful when you need test fixtures, Storybook stories or API mock responses that match your type definitions exactly — without writing mock data by hand.

Input
interface User {
  id: number
  name: string
  active: boolean
}
Output
{ "id": 1, "name": "string_1",
  "active": true }
Mode 2 — Serialization snippets

Get ready-to-use TypeScript code snippets for the most common JSON serialization patterns: basic stringify, typed wrapper functions, async fetch with typing, localStorage helpers and Node.js file write — all with correct TypeScript types.

Output snippets
const str = JSON.stringify(obj)
const parsed: T = JSON.parse(str)
await res.json() as T
Mode 3 — Interface to JSON Schema

Convert a TypeScript interface to a JSON Schema Draft-07 or 2020-12 document. TypeScript types are mapped to JSON Schema keywords: optional fields (?) are excluded from required, arrays get item types, and nested interfaces become $defs references.

Input
interface User {
  id: number
  name?: string
}
Output
{ "type": "object",
  "required": ["id"],
  "properties": {
    "id": { "type": "number" },
    "name": { "type": "string" }
  }}
When do you need TypeScript to JSON?

The four most common workflows where each mode applies.

Test fixtures and mocking

Unit tests and Storybook stories need typed mock objects that match your interfaces exactly. Mode 1 generates them from the interface definition — no manual mock writing, no risk of type mismatch between the mock and the actual interface.

API serialization patterns

TypeScript's type system disappears at runtime — you need JSON.stringify() for network requests, storage and logging. Mode 2 gives you the correct typed serialization pattern for your specific use case: fetch, axios, localStorage, or Node.js file write.

Runtime validation with AJV

TypeScript interfaces enforce types at compile time only. For runtime validation of API responses, form inputs or config files, you need a JSON Schema. Mode 3 converts your existing interfaces to a Draft-07 schema you can use with AJV, Fastify or Zod's z.fromJsonSchema().

OpenAPI specification

OpenAPI 3.0 uses JSON Schema for request and response types. Converting your TypeScript interfaces to JSON Schema gives you the components/schemas section of your OpenAPI document — keeping your type definitions as the single source of truth between compile-time types and runtime validation.

Related tools
Popular searches
typescript to json typescript interface to json typescript object to json typescript to json schema typescript to json converter ts interface to json typescript serialize json typescript to json online ts to json schema convert typescript interface to json typescript json stringify typescript interface to json schema

TypeScript parsed with
regex. No compiler needed.

TypeScript interfaces are parsed with a field-level regex — no need to load the TypeScript compiler (4MB+). The parser extracts field names, types and optionality from the interface body, covering the most common patterns used in real-world TypeScript codebases.

The three output modes share the same parser and produce output that is immediately usable: mock data for tests, serialization patterns for production code, and JSON Schema for runtime validation — all from the same interface definition.

3 modes, 1 parser
Mock JSON, serialization snippets and JSON Schema all use the same regex-based TypeScript interface parser — consistent output across all three modes.
No TypeScript compiler
The tsc compiler is 4MB+. This tool uses a lightweight regex parser that covers interface syntax without any external dependency.
Optional fields respected
Fields marked with ? are correctly handled in all three modes — omitted from required in JSON Schema, optionally included in mock data.
47 tools, always free
No file size limits, no watermarks, no account. Funded by non-intrusive display advertising only.
Frequently asked questions
Common questions about converting TypeScript to JSON.
How do I generate mock JSON from a TypeScript interface?
Select the Mock JSON mode, paste your TypeScript interface, and click Generate. The tool parses the interface fields and generates a realistic JSON object with example values for each type — ready for tests, Storybook or API mocks.
How do I serialize a TypeScript object to JSON?
Use JSON.stringify(obj) — the built-in global works identically in TypeScript and JavaScript. Select the Serialization mode to get ready-to-use TypeScript snippets with correct typing for the most common patterns: fetch, axios, localStorage and Node.js file write.
How do I convert a TypeScript interface to a JSON Schema?
Select the JSON Schema mode, paste your interface, and click Generate. TypeScript types are mapped to JSON Schema keywords: string → type: string, optional fields (?) are excluded from required, and arrays get item types inferred.
What TypeScript types does the parser support?
The parser supports: string, number, boolean, null, undefined, unknown, any, string[], number[], boolean[], Array<T>, and PascalCase type references (treated as nested objects). Optional fields marked with ? are correctly handled in all three output modes.
Why does TypeScript need JSON serialization if it has types?
TypeScript types only exist at compile time — they are erased when the code runs in the browser or Node.js. At runtime, you need JSON.stringify() to serialise objects to strings for network requests, storage and logging, exactly as in plain JavaScript.
Go up