Skip to content
POST AI agent ready /v1/schema/json-to-typescript

JSON to TypeScript API - Generate Interfaces from JSON

Infers field types from the provided JSON: strings become string, numbers become number, booleans become boolean, null becomes null, arrays recurse into T[], nested objects become inline interfaces. Keys with special characters are quoted. Cycles are broken with Record<string, unknown>.

Parameters

objectrequired

A JSON value to infer types from.

string

Root interface name.

Code examples

curl -X POST https://api.botoi.com/v1/schema/json-to-typescript \
  -H "Content-Type: application/json" \
  -d '{"json":{"id":1,"name":"Ada","active":true,"tags":["admin"]},"name":"User"}'

When to use this API

Generate types from third-party API responses

Paste a sample response from the Stripe or GitHub API, generate the interface, and drop it into your codebase. No manual typing of 30-field JSON structures.

Scaffold types for new endpoints

When designing an endpoint, sketch the response as JSON, convert to TypeScript, and use the interface as the starting point for both server types and SDK types.

Migrate from untyped to typed

For each fixture JSON file in your test suite, generate a corresponding interface. Replaces tribal-knowledge shape docs with machine-checked types.

Frequently asked questions

What is inferred for null values?
A literal null type. If you expect nullable fields, manually widen the type after generation (e.g., string | null).
How are arrays with mixed types handled?
Only the first element's type is inspected. For more accurate union types in mixed arrays, pass a sample where the array contains each variant.
Will it generate optional fields?
No. Every field is required in the output. If your real data has optional fields, add the ? modifier manually after generation.
How are cycles handled?
Self-referencing structures emit Record<string, unknown> at the cycle point. Deep cycles in user-supplied JSON are safe thanks to the visited-set guard.
Can I generate multiple interfaces?
No. One sample in, one root interface out. For multiple types, call the endpoint per sample with distinct name values, or use /v1/schema/json-to-jsonschema as an intermediate format.

Get your API key

Free tier includes 5 requests per minute with no credit card required. Upgrade for higher limits.