JSON Input

C# Output

What Is JSON to C#?

If you're integrating a third-party API in your .NET app, you'll usually get JSON docs but need typed C# classes to actually deserialize the response. Writing those classes by hand is tedious — especially with deeply nested objects. This tool generates C# POCOs from your JSON automatically. Paste a sample API response and get class definitions ready to drop into your project. They work out of the box with System.Text.Json or Newtonsoft.Json.

Conversion runs in your browser. Use the config options to set the class name, choose properties vs fields, and enable nullable types. Nothing is sent to a server.

How to Use This Tool

1

Paste JSON

Paste your JSON into the left editor or upload a file. Use Sample for example data. Set the root class name and options (Properties, Nullable) in the config panel.

2

Review the Classes

The right panel shows generated C# classes. Nested objects become separate classes. Arrays become List<T> or T[]. Add [JsonPropertyName] attributes if needed for different JSON key names.

3

Copy or Download

Use Copy or Download to get the code. Paste into your .NET project. For formatting JSON first, use the JSON Formatter. For validation, use the JSON Validator.

JSON to C# Examples

Here is an example of generating C# classes from a JSON object.

Example: Subscriber record

JSON input:

Input

Generated C# output:

Output

When JSON to C# Helps

When integrating REST APIs in .NET, ASP.NET Core, or Blazor, you need C# types for deserialization. Pasting a sample response here gives you POCOs you can use with JsonSerializer.Deserialize<T>() or Newtonsoft.Json. For API testing, Postman and jq are useful. For pulling out specific values from large responses first, use jq.

JSON to C# Examples

Example: JSON object to C# class

JSON input:

{"subscriberId":"SUB-001","planName":"Premium 4G","dataLimit":"50GB","voiceMinutes":500,"status":"active"}

Generated C# class:

public class RootObject
{
    public string SubscriberId { get; set; }
    public string PlanName { get; set; }
    public string DataLimit { get; set; }
    public int VoiceMinutes { get; set; }
    public string Status { get; set; }
}

Frequently Asked Questions

How do I deserialize JSON in C#?

Use JsonSerializer.Deserialize<YourClass>(jsonString) from System.Text.Json, or JsonConvert.DeserializeObject<YourClass>(jsonString) from Newtonsoft.Json. You need a matching C# class — generate one here by pasting your JSON.

What if my JSON keys don't match C# naming conventions?

Use [JsonPropertyName("json_key")] on the property (System.Text.Json), or [JsonProperty("json_key")] (Newtonsoft). Alternatively, configure JsonSerializerOptions.PropertyNamingPolicy to JsonNamingPolicy.CamelCase for automatic mapping.

What about nullable reference types in C#?

Enable Nullable Types in the config to generate string?, int?, etc. This is useful when JSON fields can be null or absent. You'll need #nullable enable or a nullable-aware project setting.

Is my JSON sent to a server?

No. The class generation runs entirely in your browser. Your JSON never leaves your machine, so it's safe to use with production API keys or sensitive data.

Properties vs fields — which should I use?

Properties (get; set;) are the standard for DTOs in C#. Both System.Text.Json and Newtonsoft.Json serialize public properties by default. Fields work, but they're less common for data transfer objects.

Related Tools

System.Text.Json. Newtonsoft.Json. JSON spec. RFC 8259. MDN. .NET. Postman.