Canonical: https://toolipedia.app/data-to-code-model-generator

# Data to Code Model Generator

Turn SQL CREATE TABLE statements, JSON, YAML or XML into classes, ORM models, validation schemas, migrations, GraphQL types or Protobuf messages chosen from two dropdowns.

Breadcrumbs: Toolipedia > Developer tools > Code and developer utilities > Data to Code Model Generator

## About Data to Code Model Generator

Writing the same data model in several languages by hand is slow and error prone. Paste SQL CREATE TABLE statements, or a JSON, YAML or XML sample, choose a target from the second dropdown and get code for it: TypeScript interfaces, Python dataclasses, Java records, C# classes, Go structs, Django, SQLAlchemy, Prisma, TypeORM and Sequelize models, Zod, Yup and Joi schemas, a Knex migration, CREATE TABLE for another database, GraphQL types or Protobuf messages. Foreign keys, nullability, lengths and nested objects are carried over.

## How to use Data to Code Model Generator
1. Choose what your input is: SQL CREATE TABLE statements, JSON, YAML or XML, then paste it into the input box.
2. Choose the output in the second dropdown. For JSON, YAML or XML also name the top-level model.
3. Copy or download the generated code and adjust names, defaults and relations to fit your project.

## Why use this tool?
- Private: everything happens in your browser. Nothing you enter is uploaded.
- Free, with no sign-up, no watermark and no limit on how often you use it.
- Works on phones, tablets and computers: Android, iPhone, Windows, Mac and Linux. Nothing to install.

## Also known as
- data to code model generator
- json
- yaml
- xml
- sql to classes
- sql to typescript
- sql to django models
- json to zod schema
- sql create table to prisma

## Frequently asked questions

### How are types chosen when I paste JSON or XML?

The tool infers them from the sample values: whole numbers, decimals, booleans, ISO dates, UUIDs and text. A field missing or null in some objects becomes optional, and nested objects become their own models.

### Does it handle foreign keys and composite keys?

Single-column foreign keys become relations in Django, SQLAlchemy, Prisma and TypeORM, and references in Sequelize and Knex. Composite primary keys are written for Prisma and Knex, and noted where a framework cannot express them.

### Is the generated code ready to ship?

Treat it as a first draft. Generated models are only as complete as your sample, so review lengths, defaults, indexes and relations, and run your project's formatter and tests.

### Is Data to Code Model Generator free?

Yes. Data to Code Model Generator on Toolipedia is free to use, with no sign-up and no watermark.

### Is it safe to use?

Yes. Everything is worked out in your browser, and nothing you enter is sent to our server.

### Does it work on my phone?

Yes. It works in any modern browser on Android and iPhone, as well as on tablets and computers. There's nothing to install.

### Do I need an account?

No. Just open the page and use the tool. There's no sign-up and no email needed.

## Related tools

More free tools that go well with Data to Code Model Generator:
- [SQL Schema Diff](https://toolipedia.app/sql-schema-diff)
- [JSON to XML converter](https://toolipedia.app/json-xml-converter)
- [Code Formatter and Syntax Validator for Many Languages](https://toolipedia.app/code-formatter-and-syntax-validator-for-many)
- [JSON to SQL INSERT Generator](https://toolipedia.app/json-to-sql-insert)
- [Plist to JSON Converter](https://toolipedia.app/plist-to-json-converter)
