JSON to TypeScript
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 TypeScript, and 20 more languages
Paste a sample JSON response and get typed models for your code. TypeScript is selected here, and the same tool writes Go, Python, Pydantic, Java, C#, Kotlin, Swift, Rust, Scala, Ruby, Dart, PHP, Zod, TypeBox, Valibot, Yup, GraphQL, Protobuf, Prisma and Drizzle.
Example: a GitHub-style API response
A list of repositories, where only one has a license and one key isn't a valid identifier. Each object gets an interface named after its key, the field missing from one item becomes optional (?:), and the key with a dash keeps its quotes:
Input
[
{
"id": 101,
"name": "bracely",
"full_name": "saurabhpagrut/bracely",
"private": false,
"stargazers_count": 42,
"owner": {
"login": "saurabhpagrut",
"type": "User"
},
"topics": [
"json",
"devtools"
],
"license": {
"key": "mit",
"spdx-id": "MIT"
}
},
{
"id": 102,
"name": "notes",
"full_name": "saurabhpagrut/notes",
"private": true,
"stargazers_count": 0,
"owner": {
"login": "saurabhpagrut",
"type": "User"
},
"topics": []
}
]Output
export type RepoList = Repo[];
export interface Repo {
id: number;
name: string;
full_name: string;
private: boolean;
stargazers_count: number;
owner: Owner;
topics: string[];
license?: License;
}
export interface Owner {
login: string;
type: string;
}
export interface License {
key: string;
"spdx-id": string;
}
How do I use the JSON to TypeScript?
- Paste a JSON sample, such as an API response.
- Pick the language and set the root type name.
- Copy the generated code into your project.
What does the JSON to TypeScript do?
- Nested objects become their own named types
- Optional fields detected across array items
- Numbers split into integers and floats where the language cares
- 21 languages from one sample
When to use the JSON to TypeScript
Typing an API response by hand is slow, and it drifts from the real data. Paste a real response instead and get interfaces that match it, so the editor autocompletes fields and the compiler catches a typo or a wrong type before it reaches the browser. It's the quickest way to type a third-party API that ships no types.
Each object becomes an export interface named after its key, and an array at the top level gets a type alias such as RepoList. A key missing from some items becomes optional (license?:), a value that's sometimes null becomes string | null, a field whose items disagree becomes unknown so you decide what it is, and keys that aren't valid identifiers keep their quotes. For runtime validation as well as types, pick Zod, TypeBox, Valibot or Yup in Language.
Frequently asked questions
- Interfaces or types?
- Interfaces, because they're what most style guides use for object shapes and they show up clearly in editor hints. The only type alias is for an array at the top level, which an interface can't describe.
- Why is a field typed unknown?
- Its values in the sample have different types, such as a number in one item and a string in another. unknown makes you check before using it; replace it with the union you expect, like number | string.
- Which languages are supported?
- TypeScript, Go, Python, Pydantic, Java, C#, Kotlin, Swift, Rust, Scala, Ruby, Dart, PHP, Zod, TypeBox, Valibot, Yup, GraphQL, Protobuf, Prisma and Drizzle: pick one from Language.
- How are optional fields found?
- When items in an array have different keys, keys that are missing from some items are marked optional.
- Can I generate a JSON Schema instead?
- Yes. The JSON Schema tool generates a schema from the same sample.
More JSON tools
Bracely has 108 JSON tools in one page. Related ones:
- JSON Schema Generator
- JSON to Go
- JSON to Java
- JSON to C#
- JSON to Python
- JSON to Kotlin
- JSON to Swift
- JSON to Dart
- JSON to Rust
- JSON to PHP
- JSON to Zod
- JSON to GraphQL
- JSON to Protobuf
- JSON to Pydantic
- JSON to XML
- JSON to Excel
- Mock JSON generator
- UUID generator
- Code screenshot
- HTML to JSX
- 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.7 · Changelog
Saurabh Pagrut on GitHub · LinkedIn · X · YouTube · Instagram