Skip to content
| Marketplace
Sign in
Visual Studio Code>Snippets>JSON to NestJS DTO by PrograamerNew to Visual Studio Code? Get it now.
JSON to NestJS DTO by Prograamer

JSON to NestJS DTO by Prograamer

Aamer

|
28 installs
| (0) | Free
Convert JSON objects to NestJS DTOs with class-validator, class-transformer, and Swagger decorators following official NestJS patterns. Created by Prograamer YouTube Channel.
Installation
Launch VS Code Quick Open (Ctrl+P), paste the following command, and press enter.
Copied to clipboard
More Info

JSON to NestJS DTO

A Visual Studio Code extension that converts JSON objects to NestJS DTOs with class-validator, class-transformer, and Swagger decorators.

Features

  • 🚀 Quick Conversion: Convert JSON to NestJS DTOs instantly
  • 🔧 Smart Type Detection: Automatically infers TypeScript types from JSON values
  • 🎯 NestJS Ready: Generates DTOs with proper decorators for validation and documentation
  • 🔀 Nested Objects: Handles complex nested structures by creating separate DTO classes
  • ⚙️ Configurable: Customize output with various options

Usage

Method 1: Command Palette

  1. Open Command Palette (Ctrl+Shift+P / Cmd+Shift+P)
  2. Type "Convert JSON to NestJS DTO"
  3. Select your JSON text or ensure your document contains JSON
  4. Press Enter

Method 2: Keyboard Shortcut

  • Ctrl+Shift+D (Windows/Linux) / Cmd+Shift+D (Mac): Convert selected JSON
  • Ctrl+Shift+Alt+D (Windows/Linux) / Cmd+Shift+Alt+D (Mac): Convert from clipboard

Method 3: Context Menu

  1. Select JSON text in editor
  2. Right-click and select "Convert JSON to NestJS DTO"

Example

Input JSON:

{
  "name": "John Doe",
  "age": 30,
  "isActive": true,
  "address": {
    "street": "123 Main St",
    "city": "New York"
  },
  "hobbies": ["reading", "swimming"]
}

Generated DTO:

import { IsString, IsNumber, IsBoolean, IsArray, ValidateNested, IsObject } from 'class-validator';
import { Type } from 'class-transformer';
import { ApiProperty } from '@nestjs/swagger';

export class AddressDto {
  @IsString()
  @ApiProperty({ example: "123 Main St" })
  street: string;

  @IsString()
  @ApiProperty({ example: "New York" })
  city: string;
}

export class GeneratedDto {
  @IsString()
  @ApiProperty({ example: "John Doe" })
  name: string;

  @IsNumber()
  @ApiProperty({ example: 30 })
  age: number;

  @IsBoolean()
  @ApiProperty({ example: true })
  isActive: boolean;

  @ValidateNested()
  @IsObject()
  @Type(() => AddressDto)
  @ApiProperty({ type: AddressDto })
  address: AddressDto;

  @IsArray()
  @ApiProperty({ type: [String] })
  hobbies: string[];
}

Configuration

Access extension settings via VS Code Settings (Ctrl+, → Search "JSON to NestJS DTO"):

  • Use Class Validator: Include class-validator decorators (default: true)
  • Use Class Transformer: Include class-transformer decorators (default: true)
  • Use Swagger: Include Swagger/OpenAPI decorators (default: true)
  • Make Optional: Make all properties optional by default (default: false)
  • Export Class: Add export keyword to generated classes (default: true)
  • Indent Size: Number of spaces for indentation (default: 2)

Requirements

This extension works with any JSON input and generates TypeScript code compatible with:

  • NestJS framework
  • class-validator package
  • class-transformer package
  • @nestjs/swagger package

Release Notes

1.0.0

  • Initial release
  • JSON to NestJS DTO conversion
  • Support for class-validator, class-transformer, and Swagger decorators
  • Configurable options
  • Multiple input methods

Contributing

Found a bug or have a feature request? Please open an issue on our GitHub repository.

License

This extension is licensed under the MIT License.

  • Contact us
  • Jobs
  • Privacy
  • Manage cookies
  • Terms of use
  • Trademarks
© 2025 Microsoft