JSON to C#
ConverterGenerate C# classes from sample JSON with nested types, List generics and JsonProperty attributes for .NET models, splitting nested objects into their own.
using System;
using System.Collections.Generic;
using Newtonsoft.Json;
public class Profile
{
[JsonProperty("age")]
public int Age { get; set; }
[JsonProperty("city")]
public string? City { get; set; }
}
public class RootObject
{
[JsonProperty("id")]
public int Id { get; set; }
[JsonProperty("name")]
public string? Name { get; set; }
[JsonProperty("active")]
public bool Active { get; set; }
[JsonProperty("score")]
public double Score { get; set; }
[JsonProperty("tags")]
public List<string>? Tags { get; set; }
[JsonProperty("profile")]
public Profile Profile { get; set; }
}Related Tools
About JSON to C#
Consuming JSON APIs in .NET means writing many C# classes by hand. This tool parses your sample JSON locally and generates complete C# classes: field names become PascalCase (e.g. user_id becomes UserId), nested objects become separate classes, arrays infer to List<T>, with nullable reference types (C# 8+) and nullable value types, plus Newtonsoft.Json / System.Text.Json JsonProperty attributes. Generated code works for .NET Web API models, EF Core entities, and REST client DTOs. Nothing is uploaded to any server. Note: if API fields can legally be null, enable nullable value types (like int?) so deserialization never assigns a null to an int field, avoiding runtime exceptions.
How to Use
- Open the JSON to C# tool
- Select the source and target formats
- Adjust the output options as needed
- Click the Convert button; results appear in real time
- Copy or export the result
Use Cases
- Consume REST APIs — Convert API JSON to C# classes for HttpClient/RestSharp deserialization.
- EF Core entities — Generate entity classes from database JSON samples for Entity Framework Core.
- Unity config modeling — Create type-safe C# models for Unity game configuration JSON.
- Azure Function inputs — Quickly generate input model classes for Azure Function HTTP Triggers.
- API docs modeling — Generate request/response models from JSON docs as baseline for integration tests.
FAQ
What is the difference between Newtonsoft and System.Text.Json?
Newtonsoft.Json uses [JsonProperty]; System.Text.Json uses [JsonPropertyName]. Choose based on your project: .NET Core 3.0+ defaults to System.Text.Json, while legacy projects or those needing advanced features use Newtonsoft.Json.
What are nullable reference types?
A C# 8+ feature. When enabled, reference-type fields like string become nullable (string?) and the compiler warns on potential null assignments, surfacing null-safety issues at compile time.
How are nested objects handled?
Each nested object becomes a separate class, referenced by properties on the top-level class, keeping the structure clean and reusable.
Are underscore fields converted?
Yes. They become PascalCase by default (user_id to UserId). If the API relies on original keys, add JsonProperty to preserve the mapping during deserialization.
How are nullable fields handled?
With nullable value types enabled, numeric fields generate int?/double?, and string fields generate string?. This prevents incorrect null assignments during deserialization.