Use this JSON to C# generator to create C# classes or records from JSON samples for ASP.NET Core APIs and .NET apps.
Step 1 – Paste a JSON sample
- Paste a representative JSON object or array into the left editor.
- Include nested objects, arrays, and nullable fields so types are inferred correctly.
- Use
Import to load JSON from a file, URL, or sample data.
Step 2 – Choose C# class options
- Set
Class Name and Namespace to match your project structure. - Choose a JSON framework (
System.Text.Json or Newtonsoft.Json) if you want attributes. - Enable nullable reference types so optional fields map to
string? and similar types.
Step 3 – Review the generated code
- Check field names, types, and how arrays/objects are modeled.
- Adjust options like
Root Type Name, null handling, and frameworks if available. - If a field is inferred incorrectly, tweak your sample JSON and regenerate.
Step 4 – Use the generated DTOs in .NET
- Paste the output into your project and add it to your API/DTO folder.
- Deserialize JSON into the root type using your chosen serializer.
- Keep DTOs separate from domain models when you need versioning and backward compatibility.
Step 5 – Copy or download
- Copy the output into your project or download it as a file.
- Run your formatter/linter to match your code style.
- Add JSON parsing/serialization libraries if your language requires them.
Example output (simplified)
// JSON input
{
"id": 123,
"name": "Maeve Winters",
"email": "maeve@example.com",
"active": true,
"roles": ["admin", "editor"],
"metadata": { "plan": "pro" },
"createdAt": "2024-03-01T10:15:00Z",
"score": 99.5,
"notes": null
}
// Generated C# DTOs (simplified)
public class Metadata
{
public string Plan { get; set; } = string.Empty;
}
public class Root
{
public int Id { get; set; }
public string Name { get; set; } = string.Empty;
public string? Email { get; set; }
public bool Active { get; set; }
public List<string> Roles { get; set; } = new();
public Metadata Metadata { get; set; } = new();
public DateTime CreatedAt { get; set; }
public double Score { get; set; }
public object? Notes { get; set; }
}