In this sectionGenerate
Guide to a workspace
Generate
Types, models and schemas from a sample document — ten languages, and structured-output schemas for three AI providers — from JSON, YAML, XML or CSV.
Turn a document into code
4 guidesAny format, through JSON, into a language
Pick what you have and what you want; the code is written as you type. On this pageTypeScript interfaces from a JSON API response
Interfaces from an API response, with the optional fields found and the nested types named for you. Its own pageThe other nine languages
Python, JSON Schema, Java, C#, Go, Zod, Rust, Kotlin and Swift from one document, and what each does with it. Its own pageFrom YAML, XML or CSV
A source that is not JSON is read into JSON first, and the JSON tab shows the reading. On this page
Shape the types
2 guidesSchemas for validators and models
2 guidesTurn a document into code
Any format, through JSON, into a language
Input
event.json
{
"name": "Launch party",
"seats": 120,
"price": 12.5,
"online": false,
"hosts": ["Ada", "Linus"]
}Do
- Set From to JSON, and under Language choose Python.
- In Options, under Python, set Style to Pydantic v2.
- Paste the input into the source pane, and type
Eventinto Root name, since a paste has no file name to take it from.
Result
# Generated by myjsoneditor.com — Python 3.11+
# Requires pydantic>=2
from pydantic import BaseModel
class Event(BaseModel):
name: str
seats: int
price: float
online: bool
hosts: list[str]The row above the panes reads from left to right. From names what you are pasting — JSON, YAML, XML, CSV or TSV — and Language offers the targets, five as tabs and five more under More. A second row, Structured output, holds the three AI providers. Only one target is selected across both rows at a time.
Whatever the source is, the generator only ever reads JSON. A JSON source goes straight in; anything else is read into JSON first, and the row shows that middle step. The name above the result is the file Download saves, and Copy takes the code. In the editor, Generate in the band opens a panel titled Generate code with the same targets over the document in the pane, which is the quicker route when the document is already open there.
TypeScript interfaces from a JSON API response
TypeScript is the target the page opens on, and the one most readers want. TypeScript interfaces from a JSON API response takes a users response with two unlike records through it, and explains each decision in the output: the question marks, the names of the nested interfaces, what an empty list becomes, and how a null changes a field’s type.
The other nine languages
Every language reads the same model of the data, so a field that is optional in TypeScript is optional in Rust and nullable in Java, each in its own idiom. The other nine languages runs one short list of books through all nine, side by side, with a note on each about the choices that language makes and the options that change them.
From YAML, XML or CSV
Input
service.yaml
service: billing
replicas: 3
ports:
- name: http
port: 8080
- name: metrics
port: 9090
public: falseDo
- Set From to YAML, and under Language choose TypeScript.
- In Options, under TypeScript, set Declaration to interface and Optional fields to name?: T, and tick export declarations.
- Paste the input into the source pane, and type
Serviceinto Root name, since a paste has no file name to take it from. - Press the JSON tab above the result, then the TypeScript tab.
Result
JSON
{
"service": "billing",
"replicas": 3,
"ports": [
{
"name": "http",
"port": 8080
},
{
"name": "metrics",
"port": 9090,
"public": false
}
]
}
TypeScript
export interface Port {
name: string;
port: number;
public?: boolean;
}
export interface Service {
service: string;
replicas: number;
ports: Port[];
}With From set to anything but JSON, the result grows two tabs: JSON, the document the source was read into, and one named after the target, in front. The types come only from the JSON tab, so it is the place to look when a type surprises you. Here public is optional because one port lacks it, and the ports are numbers because the YAML wrote them bare.
XML and CSV are less sure about numbers than YAML is. XML stores everything as text, so an element holding 8080 becomes a string unless Detect numbers and booleans is ticked under Read XML in Options. A CSV cell in quotes stays text, so a column with one quoted number comes out as string | number. Neither reading option is remembered. Open JSON in Editor takes that JSON to the editor, for when the reading needs fixing before the types are worth keeping.
Shape the types
Optional fields, nested types and the root name
Input
crew.json
{
"members": [
{ "name": "Ada", "email": "[email protected]" },
{ "name": "Linus" }
]
}Do
- Set From to JSON, and under Language choose TypeScript.
- In Options, under TypeScript, set Declaration to interface and Optional fields to name?: T, and tick export declarations.
- Paste the input into the source pane, and type
Crewinto Root name, since a paste has no file name to take it from. - Then set Optional fields to name: T | undefined, and type
Rosterinto Root name.
Result
The defaults
export interface Member {
name: string;
email?: string;
}
export interface Crew {
members: Member[];
}
name: T | undefined, and Roster
export interface Member {
name: string;
email: string | undefined;
}
export interface Roster {
members: Member[];
}Each target’s settings sit under its name in Options, and they are remembered: next week, in any tab, the page opens with the ones you chose. They are also shared with the editor’s Generate panel, so a setting changed there is changed here. And the collapsed Options row shows only TypeScript options, not their values. That is why every example in these guides names each setting, even one left at its default.
Root name is different. It belongs to one document: it is kept for the tab, and a new document clears it. Left empty, it shows the name the page proposes, taken from the file name — here Crew — while nested types are named after their keys, and an array’s items take the singular, so members gives Member. A typed name replaces the root’s, and leaves the types named after keys alone.
Types for one part of a document
Input
response.json
{
"data": {
"users": [
{ "id": 1, "name": "Ada", "admin": true },
{ "id": 2, "name": "Linus", "admin": false }
]
},
"meta": { "page": 1, "total": 2 }
}Do
- Set From to JSON, and under Language choose TypeScript.
- In Options, under TypeScript, set Declaration to interface and Optional fields to name?: T, and tick export declarations.
- Paste the input into the source pane, and leave Root name empty.
- Type
$.data.users[0]into Path.
Result
export interface User {
id: number;
name: string;
admin: boolean;
}
Path $.data.users[0]: this node only.A response usually wraps the part you want in an envelope of paging and metadata. Path in Options takes a JSONPath, and the generator then reads only what it selects. A path to one place gives that value, and the root is named after the last name in the path; an index at the end names it after the singular of the list above, which is how users[0] becomes User.
A path with a filter or a wildcard can match many values, so it always gives an array of them, and the types describe a list. The line under the code says which of the two you got. Convert one part of a document explains that rule in full, since Convert’s Path is the same field. In the editor, the Tree view offers Generate code from this node on every object and array row, which opens the panel on that branch by pointing instead of typing.
Schemas for validators and models
A JSON Schema, and checking the next file
A JSON Schema is the one target that can check data rather than just describe it. A JSON Schema, and checking the next file generates one from a product record, then holds the next record to it in the editor’s Schema mode, where a wrong type and a missing field are both reported with their paths.
Structured output for OpenAI, Claude and Gemini
Asking a model to answer as JSON works better with a schema to hold it to, and each provider accepts a slightly different dialect. Structured output for OpenAI, Claude and Gemini writes the three for one list of tasks, and reads the report under each that says what the provider needed changed.
About these guides
Generate writes code that describes a document. Give it a sample of the data an API returns, a config your program reads or a file a colleague exports, and it answers with the types a program needs to hold that data: interfaces, classes, structs, validators or a schema. You choose the format you have on one side and the target you want on the other, and the code on the right follows your typing.
The hard part of writing types by hand is not the typing. It is noticing which fields are missing from some records, which numbers are always whole, and what to call the object three levels down. The generator reads every record in the sample to answer those questions, so this section spends its time on why the output looks the way it does and how to steer it: which setting changes what, where the type names come from, and how to generate for one branch of a larger response.
Every example above prints the output the generator gives for its input, produced by the same code the page runs. Try it in Generate under each one opens the page on that example’s format and target with the document already in the source and named as the example names it, so the type names match. The settings the steps list are still yours to set. Like Convert, it replaces whatever this tab’s source held.
Before you rely on generated types
A sample is only a sample. The generator can describe only what it was shown. A field that happens to be present in every record you pasted comes out required, and a field that is always null comes out as null alone. The more varied the records in the sample, the closer the types come to the real contract, so paste a page of results rather than one.
Your data stays here. Reading, inference and writing the code all happen in this browser tab. Responses full of real customer records can be typed without sending them to anyone, and the page keeps working with the network off.
Open Generate, or Open the editor to generate from a document you are already working on. When the file is in the wrong format for your program rather than lacking types, Convert is the section to read.
For the parts of this page that every tool shares — Settings, the keys, the theme and what is kept between visits — see Around the app.