JSON to TypeBox
Paste or drop your data here, or open a file.
New to Bracely?
Everything stays in your browser.
Output appears here
Paste or open your data in the input box. It never leaves your browser.
JSON to TypeBox
Paste a JSON sample, such as an API response, and Bracely writes TypeBox schemas and TypeScript types for it. Each object becomes a Type.Object() schema with a Static type beside it, so one definition gives both the JSON Schema for validation and the TypeScript type.
Example: a Fastify route schema for new tickets
Two ticket requests: one has a due date and an assignee, the other has no due date and a null assignee. dueDate becomes Type.Optional, assignee a union with Type.Null(), and each schema is plain JSON Schema with a Static type beside it:
Input
[
{
"title": "Login fails on Safari",
"priority": "high",
"assignee": {
"id": 7,
"name": "Ananya"
},
"labels": [
"bug",
"auth"
],
"dueDate": "2026-11-05"
},
{
"title": "Add dark mode",
"priority": "low",
"labels": [],
"assignee": null
}
]Output
import { Type, type Static } from "@sinclair/typebox";
export const Assignee = Type.Object({
id: Type.Integer(),
name: Type.String(),
});
export type Assignee = Static<typeof Assignee>;
export const CreateTicket = Type.Object({
title: Type.String(),
priority: Type.String(),
assignee: Type.Union([Assignee, Type.Null()]),
labels: Type.Array(Type.String()),
dueDate: Type.Optional(Type.String()),
});
export type CreateTicket = Static<typeof CreateTicket>;
export const CreateTicketList = Type.Array(CreateTicket);
export type CreateTicketList = Static<typeof CreateTicketList>;
How do I use the JSON to TypeBox?
- Paste a JSON sample.
- Set the root type name, for example Order.
- Copy the TypeBox code into your project.
What does the JSON to TypeBox do?
- Type.Object schemas that are plain JSON Schema
- Static<typeof ...> types exported for each
- Type.Optional and Type.Null unions where data can be missing or null
- Nested objects become their own named types
- 20 other languages from the same sample, including TypeScript
When to use the JSON to TypeBox
TypeBox writes schemas that are JSON Schema and TypeScript types at the same time, which is why Fastify uses it for route validation: one definition checks the request at runtime and types the handler. Generating it from a real request body saves writing every field twice.
Each object becomes a Type.Object() with its Static type exported beside it. Whole numbers become Type.Integer(), a field missing from some items is wrapped in Type.Optional, and a field that's sometimes null becomes a union with Type.Null(), as assignee does in the example. Values whose types disagree become Type.Unknown(), so you decide what they should be.
Frequently asked questions
- How do I validate with it?
- In Fastify, register @fastify/type-provider-typebox and use the schema in the route. Elsewhere, compile it with TypeBox's TypeCompiler, or pass it to Ajv like any JSON Schema.
- priority should only be high, medium or low. How?
- The sample can only show that it's a string. Replace Type.String() with Type.Union([Type.Literal("high"), Type.Literal("medium"), Type.Literal("low")]) and the type narrows too.
- How does it pick TypeBox types?
- From the values in your sample: whole numbers, decimals, text, true/false, arrays and nested objects. When array items disagree, the field is made optional or widened.
- Can I generate other languages?
- Yes. Change Language to any of the others: TypeScript, Go, Python, Pydantic, Java, C#, Kotlin, Swift, Rust, Scala, Ruby, Dart, PHP, Zod, Valibot, Yup, GraphQL, Protobuf, Prisma and Drizzle.
- Is my data uploaded?
- No. Bracely runs entirely in your browser, so nothing you paste or open leaves your device.
More JSON tools
Bracely has 104 JSON tools in one page. Related ones:
- JSON to Valibot
- JSON to Yup
- JSON to Prisma
- JSON to Drizzle
- JSON to Scala
- JSON to Ruby
- JSON Schema builder
- JSON Schema validator
- JSON data dictionary
- OpenAPI from JSON
- JSON to ER diagram
- JSON Schema to TypeScript
- OpenAPI to TypeScript
- GraphQL to TypeScript
- JSON to XML
- JSON to Excel
- Mock JSON generator
- UUID generator
- CSS to Tailwind
- SQL formatter
- JSON Formatter
- JSON Validator
- JSON Viewer
- JSON Repair
- JSON Diff
- JSON to YAML
- JSON to CSV
- jq Playground
Runs entirely in your browser. Nothing you paste is uploaded. Made by Saurabh Pagrut · About · Privacy policy
Last updated · Version 6.1 · Changelog
Saurabh Pagrut on GitHub · LinkedIn · X · YouTube · Instagram