File Templates & Quick File Creation
JSON to C# Conversion
Convert JSON objects to C# classes instantly with intelligent property mapping.
Overview
Section titled “Overview”The JSON to C# feature automatically generates C# classes from JSON data, saving time and reducing errors.
Basic Usage
Section titled “Basic Usage”Simple Conversion
Section titled “Simple Conversion”Press Shift+F2 and enter:
{"name":"John","age":30}Person.csGenerates:
namespace YourNamespace{ public class Person { public string Name { get; set; } public int Age { get; set; } }}With Folder
Section titled “With Folder”Create in a specific folder:
Models/{"name":"John","age":30}User.csGenerates User.cs in the Models folder.
Nested Structures
Section titled “Nested Structures”For nested folders:
Models/Dto/{"id":1,"name":"Product"}ProductDto.csCreates folders and file automatically.
Supported JSON Features
Section titled “Supported JSON Features”Primitive Types
Section titled “Primitive Types”- Strings:
"name": "value"→string Name - Numbers:
"age": 30→int Age - Decimals:
"price": 19.99→decimal Price - Booleans:
"active": true→bool Active
Complex Types
Section titled “Complex Types”Null Values
Section titled “Null Values”"value": null→string? Value(nullable reference types)
Arrays
Section titled “Arrays”"tags": ["tag1", "tag2"]→List<string> Tags"numbers": [1,2,3]→List<int> Numbers
Nested Objects
Section titled “Nested Objects”{ "user": { "name": "John", "email": "john@example.com" }}Generates two classes: main class and nested User class.
Mixed Arrays
Section titled “Mixed Arrays”Arrays with objects:
{ "items": [ {"id": 1, "name": "Item1"} ]}Generates Item class and List<Item> property.
Generated Class Features
Section titled “Generated Class Features”Property Naming
Section titled “Property Naming”JSON keys are converted to Pascal Case:
"firstName"→FirstName"user_name"→UserName"email-address"→EmailAddress
Type Inference
Section titled “Type Inference”Types are intelligently inferred:
- Whole numbers →
int - Decimals →
decimal - ISO dates →
DateTime - Arrays →
List<T> - Nested objects → Custom classes
Code Quality
Section titled “Code Quality”Generated code includes:
- Proper formatting
- Correct namespace
- XML documentation (optional)
- Nullable reference types
- Standard conventions
Advanced Features
Section titled “Advanced Features”Multiple JSON Objects
Section titled “Multiple JSON Objects”Convert multiple JSON objects:
{"id":1,"name":"User"}User.cs, {"id":1,"title":"Post"}Post.csDefault Class Name
Section titled “Default Class Name”Without specifying a name:
{"name":"value"}Creates RootObject.cs by default.
Multiline JSON
Section titled “Multiline JSON”For complex JSON, use the full editor:
- Create a file first
- Paste JSON
- Use command “Convert JSON to C#“
Use Cases
Section titled “Use Cases”API Response Models
Section titled “API Response Models”Convert API responses:
- Copy JSON response
- Use Quick Add with JSON
- Get C# models instantly
Configuration Classes
Section titled “Configuration Classes”Convert config JSON to strongly-typed classes:
- Copy appsettings.json section
- Generate C# configuration class
- Use with Options pattern
Test Data
Section titled “Test Data”Generate test models from sample data:
- Create test JSON
- Convert to C# class
- Use in unit tests
Integration
Section titled “Integration”With Solution Explorer
Section titled “With Solution Explorer”Generated classes:
- Appear immediately in tree
- Have correct namespace
- Are ready to use
- Integrate with IntelliSense
With Existing Code
Section titled “With Existing Code”- Can reference other types
- Work with dependency injection
- Serialize back to JSON easily
Better Type Inference
Section titled “Better Type Inference”Provide sample data with:
- Realistic values
- All possible properties
- Varied data types
- Array with multiple items
Naming
Section titled “Naming”Use descriptive class names:
UserDto.csfor DTOsUserResponse.csfor API responsesUserViewModel.csfor view models
Organizing
Section titled “Organizing”Group related models:
Models/Api/{"..."}UserResponse.csModels/Dto/{"..."}UserDto.csTroubleshooting
Section titled “Troubleshooting”Invalid JSON
Section titled “Invalid JSON”If JSON is invalid:
- Check for missing quotes
- Verify comma placement
- Escape special characters
- Use online JSON validator
Wrong Types Generated
Section titled “Wrong Types Generated”If types are incorrect:
- Provide better sample data
- Manually adjust generated class
- Use specific values (not null)
Namespace Issues
Section titled “Namespace Issues”If namespace is wrong:
- Check folder structure
- Verify project root namespace
- Use namespace adjustment feature