HomeJSON ConvertersJSON to Sequelize Model Generator

JSON to Sequelize Model Generator

Convert JSON objects into Sequelize model definitions with correct DataTypes, primaryKey detection, allowNull handling, timestamps options, and module.exports — ready to paste into your Node.js project and use immediately with MySQL, PostgreSQL, SQLite, or MSSQL.

Convert JSON objects into Sequelize model definitions with correct DataTypes, primaryKey detection, allowNull handling, timestamps options, and module.exports — ready to paste into your Node.js project and use immediately with MySQL, PostgreSQL, SQLite, or MSSQL.

This tool is designed to provide a seamless experience for developers by handling complex operations directly in your browser with maximum speed and security.

100% Private
Instant Results
Customizable
Offline Ready
Dev-Friendly
Easy Export

Sequelize is a promise-based Node.js ORM (Object-Relational Mapper) that supports MySQL, MariaDB, SQLite, PostgreSQL, and MSSQL. It provides a JavaScript abstraction layer over SQL — instead of writing raw SQL queries, you define models that represent database tables and use JavaScript methods to query them. A Sequelize model definition is the JavaScript code that tells Sequelize what columns a table has, what database type each column is, what constraints apply (nullable, unique, primary key), and what default values to use. Every table you work with through Sequelize requires a model definition before you can query it.

Sequelize uses its own DataType system that maps to the underlying database types. DataTypes.STRING maps to VARCHAR(255) in MySQL and VARCHAR in PostgreSQL. DataTypes.INTEGER maps to INT in MySQL and INTEGER in PostgreSQL. DataTypes.BOOLEAN maps to TINYINT(1) in MySQL and BOOLEAN in PostgreSQL. DataTypes.JSON maps to JSON in MySQL 5.7+ and JSONB or JSON in PostgreSQL. DataTypes.DATE maps to DATETIME in MySQL and TIMESTAMP WITH TIME ZONE in PostgreSQL. The DataType choice affects not just the column type in the database but also how Sequelize serializes and deserializes values between JavaScript and the database — a BOOLEAN field in MySQL stored as 0 or 1 is automatically converted to a JavaScript true or false by Sequelize.

Writing Sequelize model definitions by hand from an existing data structure is straightforward but tedious. If you have a JSON representation of your data — from an API response, a database export, or an existing schema document — and need to create Sequelize models for those objects, mapping every field and its type manually takes time and introduces opportunities for typos in DataType names. This tool generates the complete sequelize.define() code block with all fields, DataTypes, and common options so you can paste it into your Node.js project and adjust the specifics for your database and business rules.

This tool takes a JSON object and generates a complete Sequelize model definition using sequelize.define(). It maps each JSON field to the appropriate Sequelize DataType: JSON strings become DataTypes.STRING, integers become DataTypes.INTEGER, floats become DataTypes.FLOAT, booleans become DataTypes.BOOLEAN, null values become DataTypes.STRING with allowNull: true (the most common nullable field type), and JSON objects and arrays become DataTypes.JSON. Fields named id are automatically assigned the primaryKey: true and autoIncrement: true options since id is the conventional Sequelize primary key field name. The generated code includes the require statements for Sequelize and the database connection (sequelize from '../config/database' as a conventional path), the sequelize.define() call with the model name and field definitions, and the module.exports statement. This is the complete model file structure that a Sequelize project expects — paste it into a new file in your models directory and it is immediately usable for querying. The model name in the define() call should be updated to match your table convention — Sequelize pluralizes the model name to determine the table name by default (User model queries the users table). Nested JSON objects and arrays in the input are mapped to DataTypes.JSON, which stores the value as a JSON column in the database. This is appropriate for fields that are inherently complex or variable in structure. If a nested object represents a related entity that should be a separate table — an order's line items, a user's addresses — you should replace the DataTypes.JSON mapping with a proper Sequelize association (hasMany, belongsTo) and create a separate model for the related entity. The tool generates DataTypes.JSON as a conservative starting point, not as the final recommendation for all nested structures.

1. Paste your JSON into the Input JSON field — use a single representative JSON object that shows all the fields you want in your Sequelize model. Include all fields that should become database columns, even if they are sometimes null in real data — the tool generates allowNull: true for null-valued fields. Click Load Example to see a sample multi-field JSON object before using your own data.

2. Click Convert to Sequelize Model — the tool parses every field, maps it to the appropriate Sequelize DataType, detects id fields for primaryKey assignment, generates allowNull: true for null fields, and outputs the complete model definition with require statements and module.exports in the Output Sequelize Model panel.

3. Review the generated model and update the model name — the first argument to sequelize.define() is the model name. Change 'MyModel' to the singular PascalCase name of your entity: 'User', 'Product', 'Order', 'Article'. Sequelize pluralizes this name to determine the table name by default — a model named 'User' queries the 'users' table. If your table name is different, add tableName: 'your_table_name' to the model options object.

4. Review and adjust the DataTypes for accuracy — check that the inferred types match your database schema. String fields that hold long text (descriptions, body content) should use DataTypes.TEXT not DataTypes.STRING. Integer fields used as foreign keys (userId, orderId) should match the type of the referenced primary key. Fields that should be unique (email, username) need unique: true added. Fields that represent timestamps created by Sequelize automatically (createdAt, updatedAt) should be removed from the field definitions and handled by Sequelize's timestamps option instead.

5. Copy the generated model code and paste it into your project — save it as models/User.js (or the appropriate entity name) in your Node.js project. Update the relative path in require('../config/database') to match the actual location of your Sequelize database connection file. Import the model in your application code and use Sequelize methods: User.findAll(), User.findByPk(id), User.create(data).

The most time-consuming part of starting a new Node.js API with Sequelize is writing the initial model definitions. If you already have a clear picture of your data — from an existing API, a database schema document, or a JSON sample from a collaborating service — translating that into Sequelize model code is purely mechanical: look at each field, determine the DataType, add the constraints. For a model with 15 fields, this takes 15 minutes and produces 60 lines of code that is entirely boilerplate. This tool generates those 60 lines in under a second, giving you back 15 minutes for the parts of your project that actually require judgment. The scenario where I use a Sequelize model generator most often is when working with a third-party API integration. The API returns JSON responses for its resources — users, products, orders — and I need Sequelize models to cache or store that data in my database. The JSON response tells me exactly what fields the data has, and this tool translates that directly into Sequelize model definitions. I still need to review the types (some string fields should actually be TEXT not STRING for longer content, some INTEGER fields should be BIGINT for large IDs) and add any constraints the API documentation specifies (unique email addresses, not-null names) — but the structure is already done. Sequelize also supports TypeScript through sequelize-typescript, which requires a different model definition syntax (class-based with decorators rather than sequelize.define()). The generated code from this tool is the CommonJS / JavaScript syntax using sequelize.define(). If your project uses TypeScript and sequelize-typescript, you will need to adapt the generated field definitions to the class decorator syntax — the DataTypes and field names are the same, only the structural syntax changes. For TypeScript projects, the generated code serves as a reference for the field names and types you need to define, even if the exact code structure is different.

Complete model file structure — generates the require statements for DataTypes and the database connection plus the sequelize.define() call and module.exports so you can paste a complete model file not just a partial snippet

primaryKey detection — fields named id automatically get primaryKey: true and autoIncrement: true which is the Sequelize convention for auto-incrementing primary keys

allowNull handling — JSON null fields generate allowNull: true in the field definition matching Sequelize's default behavior where non-null constraints are not enforced unless explicitly set

DataTypes.JSON for complex fields — nested objects and arrays generate DataTypes.JSON which stores the value as a database JSON column preserving the full structure

Correct DataType inference — strings map to DataTypes.STRING integers to DataTypes.INTEGER floats to DataTypes.FLOAT and booleans to DataTypes.BOOLEAN matching Sequelize's DataType system

Works with MySQL PostgreSQL SQLite and MSSQL — the generated DataTypes are Sequelize-standard and work across all databases Sequelize supports

100% browser-based — your JSON data never leaves your machine making it safe to use with internal data structures or API response samples

Instant generation — all field mapping and code generation runs locally in your browser with no server round-trip

Bootstrapping Sequelize model definitions when starting a new Node.js REST API project

Generating model scaffolds for third-party API data structures to cache or store external API responses in a database

Creating Sequelize models from JSON schema documents or OpenAPI response examples during API integration

Generating model definitions for each table when migrating an existing database to a new Node.js application with Sequelize

Quickly scaffolding models for prototype or MVP Node.js applications before formalizing the database schema

Creating Sequelize model files for use with Express.js or Fastify REST API projects

Generating model definitions when adding new entities to an existing Sequelize project

Bootstrapping models for Sequelize with TypeScript projects as a type reference before converting to the sequelize-typescript decorator syntax

Example Input

{
  "id": 1,
  "name": "Priya Singh",
  "email": "priya@learnhubly.com",
  "isActive": true,
  "score": 98.5,
  "tags": ["developer", "admin"],
  "profile": {
    "bio": "Principal Software Engineer"
  },
  "deletedAt": null
}

Example Output

const { DataTypes } = require('sequelize');
const sequelize = require('../config/database');

const User = sequelize.define('User', {
  id: {
    type: DataTypes.INTEGER,
    primaryKey: true,
    autoIncrement: true,
  },
  name: {
    type: DataTypes.STRING,
  },
  email: {
    type: DataTypes.STRING,
  },
  isActive: {
    type: DataTypes.BOOLEAN,
  },
  score: {
    type: DataTypes.FLOAT,
  },
  tags: {
    type: DataTypes.JSON,
  },
  profile: {
    type: DataTypes.JSON,
  },
  deletedAt: {
    type: DataTypes.STRING,
    allowNull: true,
  },
});

module.exports = User;

Data Type Mismatch Between Databases: Sequelize DataTypes map to different underlying SQL types depending on the database. DataTypes.STRING is VARCHAR(255) in MySQL but just VARCHAR in PostgreSQL. DataTypes.BOOLEAN is TINYINT(1) in MySQL but BOOLEAN in PostgreSQL. DataTypes.DATE is DATETIME in MySQL but TIMESTAMP WITH TIME ZONE in PostgreSQL. If the generated model produces unexpected behavior, check whether the Sequelize DataType maps to the column type your specific database expects. For MySQL-specific or PostgreSQL-specific types, use Sequelize.literal() or the database-specific DataType options.

Invalid JSON Input: The tool requires valid JSON to generate a model. If your JSON has syntax errors — missing commas, unquoted keys, trailing commas — the conversion fails. Use the JSON Formatter and Validator tool to fix any syntax errors first, then paste the corrected JSON here.

Generated Model File Path Mismatch: The generated model code uses require('../config/database') as the path to the Sequelize connection. If your project structure is different — the config file is in a different location, named differently, or uses ES module imports rather than CommonJS require — update the import path before using the model. In ES module projects using import/export syntax, convert the require() calls to import statements: import { DataTypes } from 'sequelize' and import sequelize from '../config/database.js'.

Model Name Pluralization Creating Wrong Table Name: Sequelize automatically pluralizes the model name to determine the table name — a model defined as 'User' queries the 'users' table, 'Person' queries 'people', 'Category' queries 'categories'. If your table name is different from the pluralized model name, add tableName: 'your_actual_table_name' as a second argument option in the sequelize.define() call: sequelize.define('User', { fields }, { tableName: 'app_users' }). This overrides the automatic pluralization.

CreatedAt and UpdatedAt Fields Generating as Regular Columns: Sequelize automatically manages createdAt and updatedAt timestamp columns by default without you declaring them in the model definition. If your JSON sample includes these fields and the generated model includes them as DataTypes.DATE or DataTypes.STRING fields, remove them from the field definitions. Sequelize will create and update these columns automatically. If you do not want Sequelize to manage timestamps at all, add timestamps: false to the model options.

Using DataTypes.JSON for nested objects that should be separate tables with associations

Fix: DataTypes.JSON stores the entire nested object as a JSON column in a single database row. This is appropriate when the nested data is truly subordinate and will always be read with the parent record — a user's preferences object, a product's metadata, a configuration blob. It is not appropriate when the nested data represents entities that have their own lifecycle, need to be queried independently, or are referenced by multiple parent records. An order's line items, a post's comments, or a user's addresses should each be separate tables with Sequelize associations (hasMany, belongsTo, belongsToMany). Replace DataTypes.JSON for these cases with a proper association and create a separate model.

Not adding unique constraints to fields that should be unique in the database

Fix: The generated model does not add unique: true to any field because uniqueness cannot be inferred from a JSON sample value. Fields like email, username, and SKU typically need database-level unique constraints. Add unique: true to the field definition: email: { type: DataTypes.STRING, unique: true }. For unique constraints across multiple columns (a user can only have one address of each type), use the indexes option in the model options object: { indexes: [{ unique: true, fields: ['userId', 'addressType'] }] }. Without unique constraints, Sequelize will not prevent duplicate values at the database level.

Forgetting to set allowNull: false for fields that should be required

Fix: By default, Sequelize fields are nullable — a record can be inserted without providing a value for any field. The generated model only sets allowNull: true explicitly for JSON null fields. For fields that should be required — name, email, the foreign key in a belongsTo association — you must explicitly add allowNull: false. Without it, Sequelize allows INSERT operations with those fields missing, and you will find records in your database with null values for fields that should always be present. Add allowNull: false to every field that must be present for a record to be valid.

Using DataTypes.STRING for long text content that exceeds 255 characters

Fix: Sequelize's DataTypes.STRING maps to VARCHAR(255) in MySQL by default — it can only store up to 255 characters. For longer text content — article bodies, product descriptions, log messages, comment text — use DataTypes.TEXT which maps to TEXT in MySQL and TEXT in PostgreSQL with no length limit. DataTypes.STRING also has a length option: DataTypes.STRING(1000) for VARCHAR(1000), but for anything that might be longer than a few hundred characters, TEXT is safer. The generated model uses STRING for all string fields by default — review any fields that store variable-length content and change them to DataTypes.TEXT.

Not understanding the difference between Sequelize validation and database constraints

Fix: Sequelize has two levels of data checking: validations and constraints. Validations run in JavaScript before the SQL query is sent — they catch errors in your application code before they reach the database. Constraints are enforced at the database level — they reject invalid data even if it bypasses your application code. The allowNull: false option is a constraint — Sequelize adds a NOT NULL constraint to the database column AND validates in JavaScript. The validate option in a field definition (validate: { isEmail: true }) is a validation only — it runs in JavaScript but does not add a CHECK constraint to the database. For critical data integrity, use both: allowNull: false for not-null requirements and validate options for format requirements, plus database-level constraints for uniqueness.

Does it handle associations?

The tool generates single model definitions — associations like hasMany, belongsTo, hasOne, and belongsToMany are not generated because they depend on the relationships between multiple models, not just the structure of a single JSON object. After generating the individual models for your entities, define associations in your model files or in a separate associations setup file: User.hasMany(Post, { foreignKey: 'authorId' }) and Post.belongsTo(User, { foreignKey: 'authorId' }). The generated models are the starting point — associations are the next step you define based on your domain model.

Does it support MySQL, PostgreSQL, SQLite, and MSSQL?

Yes. The generated Sequelize model code uses standard Sequelize DataTypes (DataTypes.STRING, DataTypes.INTEGER, DataTypes.BOOLEAN, etc.) that Sequelize maps to the appropriate underlying SQL types for each database dialect. The same model definition works across MySQL, MariaDB, PostgreSQL, SQLite, and MSSQL without modification. The only difference is in the actual database column types Sequelize creates — DataTypes.BOOLEAN creates TINYINT(1) in MySQL and BOOLEAN in PostgreSQL. Your application code works identically regardless of the database.

Is it safe for sensitive data?

Yes. All JSON parsing and Sequelize model code generation runs entirely in your browser using JavaScript. Your JSON payload data — including field names, internal data model structures, and sample values that may indicate your application's domain — never leaves your machine and is never transmitted to any server. This is relevant for teams where internal data model structure is considered proprietary or where API response schemas contain information about business logic.

How do I use the generated model with Sequelize associations?

After generating and saving your model files, define associations in each model file or in a central index.js that imports all models. For a User that has many Posts: in User.js or after the model definition, add User.associate = (models) => { User.hasMany(models.Post, { foreignKey: 'authorId', as: 'posts' }) }. In Post.js: Post.associate = (models) => { Post.belongsTo(models.User, { foreignKey: 'authorId', as: 'author' }) }. Then in your database initialization, call model.associate(models) for each model. This pattern is the standard Sequelize project structure.

What is the difference between DataTypes.STRING and DataTypes.TEXT?

DataTypes.STRING maps to VARCHAR(255) in MySQL — it can store up to 255 characters. DataTypes.STRING(500) maps to VARCHAR(500). DataTypes.TEXT maps to TEXT in MySQL and TEXT in PostgreSQL — it stores unlimited length text. Use DataTypes.STRING for short, fixed-length values like names, email addresses, status codes, and URLs (though long URLs may exceed 255 characters). Use DataTypes.TEXT for variable-length content that might be longer — article bodies, product descriptions, user bios, comment text, log messages. The generated model uses DataTypes.STRING for all JSON string fields — review and change to TEXT for any field that will store long content.

How do I add timestamps (createdAt, updatedAt) to my Sequelize model?

Sequelize adds createdAt and updatedAt columns automatically to every model by default — you do not need to declare them in the field definitions. When you use Model.create() Sequelize sets createdAt and updatedAt automatically. When you use Model.update() Sequelize updates updatedAt automatically. If the generated model includes createdAt or updatedAt as field definitions (because they appeared in your JSON sample), remove them and let Sequelize manage them. To disable automatic timestamps entirely, add timestamps: false to the model options: sequelize.define('User', { fields }, { timestamps: false }).

Does it work with Sequelize TypeScript (sequelize-typescript)?

The generated code uses the CommonJS require() syntax and the sequelize.define() API which is the standard JavaScript Sequelize approach. The sequelize-typescript package uses a different syntax — class-based models with TypeScript decorators: @Table, @Column, @Model. If your project uses sequelize-typescript, the generated code is a useful reference for field names and types, but you will need to convert the structure. Each field declaration like name: { type: DataTypes.STRING } becomes a class property with the @Column decorator: @Column(DataTypes.STRING) name: string. The DataTypes themselves are the same — only the structural syntax changes.

How do I run database migrations with the generated model?

The generated model defines the JavaScript interface to the database but does not create the database table. To create the table in the database, you have two approaches. First, for development: use sequelize.sync() which creates tables that do not exist based on your model definitions — sequelize.sync({ force: true }) drops and recreates. Second, for production: use Sequelize CLI migrations. Install sequelize-cli and run npx sequelize-cli migration:generate --name create-users to generate a migration template, then copy the field definitions from the generated model into the migration's up() function using queryInterface.createTable(). Migrations are the correct production approach because they give you version-controlled, reversible database changes.