What this converter does
It reads your JSON the way a C# deserializer will, then writes the classes that match it. Every nested object becomes its own class, named after the property that holds it. Arrays become List<T> or T[], with the item class named in the singular: "categories" gives you List<Category>.
When the JSON contains an array of objects, all the items are merged. A key that appears in only some items, or is null in one of them, becomes nullable. That is the difference between classes that fit your sample and classes that fit your data.
How to convert JSON to C# step by step
Paste a real response
Use a response with every field filled in, and for arrays, several items. The converter can only type what it sees: an empty array becomes
List<object>and a key that is alwaysnullbecomesobject?.Pick the serializer you use
System.Text.Json and Newtonsoft.Json use different attributes,
[JsonPropertyName]and[JsonProperty]. Pick the one your project references.Choose class or record, List or array
Records with
initsetters suit DTOs you do not change after deserializing.List<T>is the common choice;T[]is lighter if you never add items.Check the types, then copy
Read the numeric types before you paste. Prices should usually be
decimal; switch the Fractions option if so.
How JSON values map to C# types
| JSON value | C# type | Note |
|---|---|---|
42 | int | Whole numbers that fit in 32 bits |
3000000000 | long | Whole numbers beyond int.MaxValue |
19.99, 1.0, 1e3 | double or decimal | Your choice under Fractions |
true | bool | |
"2024-05-01T10:00:00Z" | DateTime | ISO 8601 dates, with or without a time |
"2024-05-01T10:00:00+02:00" | DateTimeOffset | An explicit offset only survives in DateTimeOffset |
"3f2504e0-4f89-..." | Guid | |
null only | object? | Give it a sample value to get a real type |
[1, "a"] | List<object> | Mixed arrays have no common type |
Common mistakes
- Pasting JavaScript instead of JSON causes most of the confusion here: single quotes, unquoted keys and trailing commas are valid in JavaScript but not in JSON. The converter reports the line and column.
doubleis a poor choice for money, since0.1 + 0.2does not equal0.3in binary floating point. Usedecimalinstead.- Deleting the attributes breaks deserialization without an error. System.Text.Json matches names case-sensitively by default, so a
Nameproperty stays empty without[JsonPropertyName("name")], unless you keep the attribute or configureJsonSerializerDefaults.Web. - A single sample rarely shows every optional field. Paste several items as an array so the nullability comes out right.
FAQ
Is my JSON sent to a server?
No. The converter runs entirely in your browser. Nothing you paste is uploaded or stored.
Why does every property have a JsonPropertyName attribute?
System.Text.Json matches names case-sensitively by default, so the JSON key "name" does not bind to Name without it. If you use JsonSerializerDefaults.Web or PropertyNameCaseInsensitive, you can drop them. Newtonsoft.Json is case-insensitive by default, so the Newtonsoft option only adds attributes where names really differ, such as user_id.
Why is a property nullable when my sample has a value?
For arrays of objects, every item is merged. A key that is null or missing in any item becomes nullable, because the real data can omit it. Turn off "Keys missing from some items are nullable" if you know better.
Should I use double or decimal?
decimal for money and anything where exact base-10 digits matter. double for measurements and scientific values.
When should I pick a record instead of a class?
Records give value equality and init-only properties, which suits DTOs you do not modify after deserializing. Both serializers can populate them.