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
- Open Command Palette (
Ctrl+Shift+P
/ Cmd+Shift+P
)
- Type "Convert JSON to NestJS DTO"
- Select your JSON text or ensure your document contains JSON
- 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
- Select JSON text in editor
- 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.