This reads Sequelize models written in plain JavaScript, sequelize.define("User", {...}) or Model.init({...}, {...}), and turns them into example JSON. With no type annotations to go on, each attribute's value is chosen from its DataTypes entry.
It suits older Node.js servers running Express and Sequelize without TypeScript, where the model file is the only description of what an API response or seed row looks like.
Sequelize (JS) box. Leftover require lines and module.exports are fine.{ "User": {...}, "Post": {...} }.timestamps, paranoid or a renamed createdAt are reflected, then copy.class Reservation extends Model {}
Reservation.init(
{
code: { type: DataTypes.UUID, defaultValue: DataTypes.UUIDV4, primaryKey: true },
guests: DataTypes.SMALLINT,
checkIn: DataTypes.DATEONLY,
arrivalTime: DataTypes.TIME,
options: DataTypes.JSONB,
tags: DataTypes.ARRAY(DataTypes.STRING),
},
{ sequelize, modelName: "Reservation", updatedAt: false }
);{
"code": "00000000-0000-0000-0000-000000000000",
"guests": 0,
"checkIn": "1970-01-01",
"arrivalTime": "00:00:00",
"options": {},
"tags": [
""
],
"createdAt": "1970-01-01T00:00:00.000Z"
}code has primaryKey: true, so no id is added, and its defaultValue is DataTypes.UUIDV4, a generator rather than a literal, so the placeholder UUID is shown. updatedAt: false leaves createdAt as the only timestamp, and DATEONLY, TIME, JSONB and ARRAY(STRING) become a date string, a time string, an empty object and a one-element array.
DataTypes.STRING, TEXT, CHAR → ""; INTEGER, BIGINT, FLOAT, DECIMAL → 0; BOOLEAN → false.DATE gives 1970-01-01T00:00:00.000Z, DATEONLY gives 1970-01-01 and TIME gives 00:00:00.UUID becomes an all-zero UUID string, ENUM("admin", "user") its first value, and JSON/JSONB an empty object.ARRAY(DataTypes.STRING) follows its element type, and VIRTUAL(DataTypes.STRING) is filled from the inner type.timestamps: false, updatedAt: false, createdAt: "created_on" and paranoid: true add, drop or rename the date attributes.{ type: ..., allowNull: ... } and the short form DataTypes.X are understood.Start from the output when writing the object array for queryInterface.bulkInsert, so key names and types match the model. Remove the generated id and timestamps where the database fills them.
Without TypeScript it is hard to tell what JSON a model sends just by reading it. Running each model file through here gives a quick map of the API's response shapes.
defaultValue ("pending", 1, true) becomes the sample value. Generated defaults like DataTypes.NOW, DataTypes.UUIDV4 or sequelize.fn(...) fall back to the type's placeholder.hasMany and belongsTo live outside the model definition, so they are not in the output. Add data you load with include by hand.DECIMAL usually comes back as a string at runtime, but the example shows 0.GEOMETRY, become null.underscored: true. Why is it createdAt, not created_at?underscored only changes database column names to snake_case. Attribute names used by toJSON() stay createdAt, so the output matches. To change the JSON key as well, name it explicitly with createdAt: "created_at".
class User extends Model {} and User.init() are separate?Yes. The identifier right before .init( is used as the model name, and the first argument is read as the attribute map.
Use the Sequelize (TS) to JSON page for sequelize-typescript models with @Table and @Column. That page reads property types instead of DataType.