Convert JSON to C# Classes: System.Text.Json vs Newtonsoft
A generator gives you a working first draft of the classes. The details that bite later are property name matching, number types and nullability.
Updated
Try it now: JSON to C# Converter. It runs in your browser, with no signup.
Start from a sample object
Paste one representative JSON object. The generator creates a class for the root and a class for each nested object, and arrays become List<T>.
{
"id": 42,
"user_name": "ada",
"is_active": true,
"tags": ["dev", "math"]
}Map JSON names to C# names
In the JSON to C# Converter, the Property attributes menu adds either style to every property.
// System.Text.Json
using System.Text.Json.Serialization;
public class User {
[JsonPropertyName("id")] public int Id { get; set; }
[JsonPropertyName("user_name")] public string UserName { get; set; }
}
// Newtonsoft.Json
using Newtonsoft.Json;
public class User {
[JsonProperty("id")] public int Id { get; set; }
[JsonProperty("user_name")] public string UserName { get; set; }
}Case sensitivity: the usual surprise
System.Text.Json matches property names case-sensitively by default, so "name" will not fill a property called Name unless you opt in. Newtonsoft.Json matches case-insensitively by default.
- To map snake_case keys without an attribute on every property, set PropertyNamingPolicy = JsonNamingPolicy.SnakeCaseLower (.NET 8 and later).
var options = new JsonSerializerOptions {
PropertyNameCaseInsensitive = true,
PropertyNamingPolicy = JsonNamingPolicy.CamelCase
};
var user = JsonSerializer.Deserialize<User>(json, options);Fix the types a sample cannot reveal
- Numbers: one sample cannot tell int from long, double or decimal. Use decimal for money, long for large IDs, int for small counts.
- Nullable values: a null or missing field needs a nullable type, such as string? or int?.
- Dates: ISO 8601 strings such as 2026-11-01T10:00:00Z deserialize into DateTime or DateTimeOffset.
- Arrays of mixed types: the generator cannot infer a single type, so define a proper model.
- Keys that are C# keywords, such as class or event, need an @ prefix or an attribute.
Records for immutable models
For read-only data transfer objects, a positional record is shorter. System.Text.Json can deserialize records through their constructor.
public record User(int Id, string UserName, bool IsActive, List<string> Tags);
Frequently asked questions
Which library should I pick for a new project?
System.Text.Json is built into .NET and is the default choice. Use Newtonsoft.Json when you rely on its features or already depend on it.
Can I convert a JSON array to a class?
Paste a single object from the array. The converter expects the root value to be an object, and arrays of objects inside it become List<T>.
Why is a property null after deserializing?
The most common causes are a name mismatch (case sensitivity or snake_case), a missing setter, or a type the serializer cannot convert.

