Free & open source — no account required
Free & open source — no account required
This technical guide provides an in-depth analysis of the json to typeorm entity engine, best practices for implementation, and data security standards.
TypeORM entities are the bridge between your database tables and TypeScript classes. When you have a JSON API response or sample payload and need to persist it, writing the entity by hand means translating each field to a @Column() decorator with the right type, handling nullable columns, and adding the standard audit fields (createdAt, updatedAt). Generating TypeORM entities from JSON automates the column type inference and scaffold, so you can focus on relationships and business logic.
// Input JSON
{
"order_ref": "ORD-2024-8821",
"customer_email": "jane@example.com",
"total_amount": 149.99,
"status": "pending",
"metadata": { "source": "web", "campaign": "summer" },
"shipped_at": null,
"notes": null
}
// Generated TypeORM Entity
import { Entity, PrimaryGeneratedColumn, Column, CreateDateColumn, UpdateDateColumn } from 'typeorm';
@Entity('roots')
export class Root {
@PrimaryGeneratedColumn('uuid')
id!: string;
@Column()
order_ref!: string;
@Column()
customer_email!: string;
@Column('double')
total_amount!: number;
@Column()
status!: string;
@Column('jsonb')
metadata!: any;
@Column({ nullable: true })
shipped_at!: string | null;
@Column({ nullable: true })
notes!: string | null;
@CreateDateColumn()
createdAt!: Date;
@UpdateDateColumn()
updatedAt!: Date;
}
Rename the entity and table:
// Before
@Entity('roots')
export class Root { ... }
// After
@Entity('orders')
export class Order { ... }
Use the right column type for monetary values: The generator uses 'double' for any number. For money, switch to decimal to avoid floating-point rounding:
// Generated
@Column('double')
total_amount!: number;
// Refined — store as decimal, use string in TypeScript to avoid JS float issues
@Column({ type: 'decimal', precision: 10, scale: 2 })
total_amount!: string;
Add enum constraints for status fields:
export enum OrderStatus {
Pending = 'pending',
Confirmed = 'confirmed',
Shipped = 'shipped',
Delivered = 'delivered',
Cancelled = 'cancelled',
}
@Column({ type: 'enum', enum: OrderStatus, default: OrderStatus.Pending })
status!: OrderStatus;
Add relationships: The generator doesn't infer foreign keys or relations. Add them manually after reviewing the entity structure:
import { ManyToOne, JoinColumn } from 'typeorm';
import { Customer } from './customer.entity';
@ManyToOne(() => Customer, (customer) => customer.orders)
@JoinColumn({ name: 'customer_id' })
customer!: Customer;
The generator automatically adds @CreateDateColumn() and @UpdateDateColumn() if createdAt / updatedAt aren't already in your JSON. These are managed by TypeORM — never set them manually in your application code:
@CreateDateColumn() // set once on INSERT, never updated
createdAt!: Date;
@UpdateDateColumn() // updated automatically on every UPDATE
updatedAt!: Date;
// For soft-delete support, add:
import { DeleteDateColumn } from 'typeorm';
@DeleteDateColumn() // set on soft-delete, null otherwise
deletedAt?: Date;
The generator assigns 'jsonb' to nested object fields. JSONB is PostgreSQL-specific and supports indexing and querying into the nested structure. For MySQL, use 'json' instead. If you know the shape of the nested object, type it properly:
// Generated
@Column('jsonb')
metadata!: any;
// Refined — type the structure you actually store
interface OrderMetadata {
source: 'web' | 'mobile' | 'api';
campaign?: string;
}
@Column({ type: 'jsonb', nullable: true })
metadata!: OrderMetadata | null;
Why does the generator use ! (definite assignment) on every property? TypeORM entities are instantiated without constructor arguments — TypeScript's strict mode would flag uninitialized properties. The ! tells TypeScript "I know this will be set by the ORM."
Can I use this with MySQL or SQLite? Yes. The generated entity works across databases — adjust column types as needed: 'jsonb' → 'json' for MySQL, or serialize to 'text' for SQLite.
What about the id field? If your JSON doesn't have an id field, the generator adds @PrimaryGeneratedColumn('uuid') automatically. If your JSON has id, it's treated as a regular column — rename and add the primary key decorator yourself.
Is my JSON sent to a server? No. TypeMorph runs entirely in your browser — database schemas often contain sensitive field names and structure, and none of it leaves your machine.
Is the processing local-only?
Absolutely. TypeMorph operates entirely within your browser's sandbox. We use Web Workers for high-performance computation without ever transmitting your JSON, SQL, or API data to a remote server.
Can I use this for enterprise projects?
Yes. The tool is designed for professional software engineers who require GDPR compliance and data privacy. It is trusted by developers at top-tier startups and financial institutions.