Convert TypeORM entities to JSON!

Input TypeORM entities (@Entity, @Column) to generate example JSON! Handy for API tests and mock request bodies.
TypeORM
Result
 

Convert TypeORM entities to JSON!

Paste TypeORM entity classes and get the JSON shape those entities produce when you return them from an API, filled with placeholder values. It is meant for NestJS or Express projects that send entities straight back in responses and need Swagger examples or request/response samples to agree on with the frontend.

Values come from the TypeScript type on each property, not from @Column options. A column declared @Column({ type: "decimal" }) with price: number therefore comes out as the number 0.

How to use

  1. Paste the entity file into the TypeORM box. Include related entities and enums so nested objects can be filled in.
  2. The Result box updates as you type. An entity that no other entity references becomes the top-level JSON object; if there are several unrelated entities, each appears under its class name.
  3. Grab the JSON with the copy button at the top right of the result, or press Ctrl/⌘+Enter.

Example

Input (TypeORM)
enum Genre { Novel = "novel", Essay = "essay" }

@Entity()
export class Author {
  @PrimaryGeneratedColumn()
  id: number;

  @Column()
  name: string;
}

@Entity()
export class Book {
  @PrimaryGeneratedColumn("uuid")
  id: string;

  @Column({ type: "enum", enum: Genre })
  genre: Genre;

  @Column({ type: "decimal", nullable: true })
  price: number | null;

  @ManyToOne(() => Author)
  author: Author;

  @Exclude()
  @Column()
  internalCode: string;
}
Output (JSON)
{
  "id": "",
  "genre": "novel",
  "price": 0,
  "author": {
    "id": 0,
    "name": ""
  }
}

Book references Author, so Book is the root and author is nested inside it. internalCode is dropped because of @Exclude(), and price, typed number | null, follows the first non-null type and becomes 0. The uuid primary key is typed string, so it is an empty string.

Supported features

  • @ManyToOne and @OneToOne relations become nested objects; Post[] from @OneToMany or @ManyToMany becomes a one-element array.
  • Lazy relations (Promise<Post[]>) and the ESM Relation<User> wrapper are unwrapped to the inner type.
  • TypeScript enums use the first member's value: the string for string enums, the number for numeric ones.
  • Fields marked with class-transformer's @Exclude(), static fields, methods and getters are left out.
  • Date properties (from @CreateDateColumn and similar) become ISO strings like 1970-01-01T00:00:00.000Z.
  • Types common on jsonb columns, such as Record<string, number>, are shown as {"key": 0}.
  • When entities reference each other, the second visit is cut off with null or an empty array so nesting stays finite.

Use cases

Swagger examples in NestJS controllers

Controllers that return entities directly still need an example payload for @ApiResponse. Paste the entity file and replace the placeholder values in the result with realistic ones.

Previewing loaded relations

When you query with relations: ["author"], the frontend wants to know how deep the response nests. The output makes it obvious which relation fields are objects and which are arrays.

Fixtures for e2e tests

Use the output as the skeleton of a request body for supertest POST calls. Delete generated fields like id and the timestamps, then fill in the rest.

Notes and limitations

  • @Column options such as nullable, default or length are not read; the value comes from the property type or a literal initializer (status = "draft"). If a column can be null, change that value to null yourself.
  • Several @Entity classes that don't reference each other are all converted, keyed by class name ({ "Book": {...}, "Author": {...} }). Entities that do reference each other still produce one nested root.
  • Classes that are imported rather than pasted are unknown to the tool and show up as null.
  • @Expose, serialization groups and @Transform used with ClassSerializerInterceptor are not applied.

FAQ

Why is my @PrimaryGeneratedColumn("uuid") an empty string?

Only the property type decides the value. id: string gives ""; the "uuid" argument in the decorator is not read. For documentation, swap in a UUID-shaped value afterwards.

Is this really what my API returns when it sends an entity?

It matches JSON.stringify of a fully loaded entity. Relations you did not load with relations are simply missing from the real response, so treat relation fields in the output as the loaded case.

The decimal column shows a number, but my API returns a string. Why?

The PostgreSQL and MySQL drivers return decimal values as strings to avoid precision loss. Declare the property as price: string in the entity and the output, like your real data, will be a string.