JSON to NestJS DTO Converter

Generate NestJS DTO classes from sample JSON when your controller layer needs Swagger-ready request and response contracts without writing ApiProperty decorators by hand.

How to use

  1. Paste a representative JSON payload that mirrors the request body or response shape your NestJS controller actually exposes.
  2. Review the generated DTO classes, nested child DTOs, and `@ApiProperty` decorators for optional fields and collection metadata.
  3. Copy the output into your NestJS module and add validation decorators, class-transformer rules, or naming tweaks that match your controller boundary.

Benefits

  • Produces NestJS-friendly DTO scaffolding that fits controller contracts and generated Swagger docs.
  • Saves time on nested DTO authoring when real payloads are larger than a hand-written example.
  • Keeps API transport classes explicit without mixing them into persistence entities or domain models.

Best use cases

  • NestJS REST controllers that need request and response DTOs from real payload examples.
  • Backend teams documenting APIs with Swagger and wanting faster contract scaffolding.
  • Projects separating controller-layer DTOs from entities, services, and domain-specific models.

NestJS DTO tips

  • Treat the generated DTOs as transport-layer scaffolding and add class-validator decorators separately when your endpoints need runtime validation.
  • Review optional properties carefully so Swagger docs reflect the real API contract instead of only the pasted sample.
  • Keep generated DTOs in dedicated controller or contracts folders to avoid coupling them directly to persistence models.

Implementation tips

  • Treat the generated DTOs as transport-layer scaffolding and add class-validator decorators separately when your endpoints need request validation.
  • Review optional fields and DTO naming before wiring the classes into public controller contracts.
  • Keep generated DTOs separate from persistence entities or richer domain models so Nest boundary types stay maintainable.

Sample JSON

{
  "id": 101,
  "name": "Ada Lovelace",
  "active": true,
  "roles": ["admin", "editor"],
  "profile": {
    "email": "ada@example.com",
    "score": 9.8
  }
}

Sample output

import { ApiProperty } from '@nestjs/swagger';

export class UserModelDto {
  @ApiProperty({ example: 1 })
  id: number;

  @ApiProperty({ example: "string" })
  name: string;

  @ApiProperty({ example: true })
  active: boolean;

  @ApiProperty({ type: () => ProfileDto })
  profile: ProfileDto;
}

export class ProfileDto {
  @ApiProperty({ example: "string" })
  email: string;
}

FAQ

Why use the NestJS DTO route instead of TypeScript or JSON Schema output?

Choose the NestJS DTO route when your target framework is NestJS and you want class-based DTOs with Swagger decorators. Use TypeScript or schema routes when you need framework-neutral contracts or validator-first artifacts outside Nest.

Do the generated NestJS DTOs include request validation decorators?

The generated output focuses on Swagger-ready `@ApiProperty` decorators and DTO class structure. Add class-validator decorators yourself when the endpoint contract needs runtime validation rules.