JSON to TypeScript
Generate TypeScript interfaces from a JSON sample: nested objects become named interfaces, arrays collapse to their element type, mixed arrays become unions, and keys that need quotes are handled. Deterministic — the same JSON always produces the same types.
Worked examples
Nested API payload
GET /api/v1/dev/json-to-ts?json=%7B%22user%22%3A%20%7B%22name%22%3A%20%22Ada%22%2C%20%22admin%22%3A%20false%2C%20%22tags%22%3A%20%5B%22x%22%2C%20%22y%22%5D%7D%2C%20%22count%22%3A%203%7D
Result: 2 type(s) generated: Root, User
Array of objects
GET /api/v1/dev/json-to-ts?json=%5B%7B%22id%22%3A%201%2C%20%22name%22%3A%20%22a%22%7D%2C%20%7B%22id%22%3A%202%2C%20%22name%22%3A%20%22b%22%7D%5D&rootName=Items
Result: 2 type(s) generated: Item, Item2
Mixed array
GET /api/v1/dev/json-to-ts?json=%7B%22values%22%3A%20%5B1%2C%20%22two%22%2C%20true%5D%7D
Result: 1 type(s) generated: Root
Machine API (x402)
$0.01 / callThis tool is also a JSON API for AI agents. Requests without payment receive 402 Payment Required plus instructions; agents pay USDC on Base via the x402 protocol — no accounts, no API keys.
GET /api/v1/dev/json-to-ts?json=%7B%22user%22%3A%20%7B%22name%22%3A%20%22Ada%22%2C%20%22admin%22%3A%20false%2C%20%22tags%22%3A%20%5B%22x%22%2C%20%22y%22%5D%7D%2C%20%22count%22%3A%203%7D HTTP/1.1
Host: agentstoolshub.com
→ 402 (payment required, instructions in headers)
→ 200 (after X-PAYMENT header; JSON body below)
{
"tool": "dev/json-to-ts",
"input": {"json":"{\"user\": {\"name\": \"Ada\", \"admin\": false, \"tags\": [\"x\", \"y\"]}, \"count\": 3}"},
"result": { "value": 2, "answer": "2 type(s) generated: Root, User" }
}Agent docs: /llms.txt · OpenAPI spec · integration guide
About this tool
Turns a JSON sample into paste-ready TypeScript: nested objects get PascalCase interfaces, arrays of objects reference the element type, heterogeneous arrays become union types, and odd keys are quoted correctly. Deterministic output — safe to regenerate whenever an API shape changes.
Frequently asked questions
How are optional fields handled?
A sample only shows present fields, so everything is emitted required. Optional markers are a design decision the sample can't prove — add '?' where a field is genuinely absent sometimes.
How are type unions in arrays handled?
An array mixing primitives becomes a union of the observed primitive types; an array mixing objects would union their inline shapes. For precise control, hand-edit the generated source.