JSON to C# Class Converter
Software · 2 inputs · Free
JSON to C# Class Converter
Parameters
What is this tool?
JSON to C# Class Converter helps developers with encoding, encryption and text processing. Generates C# classes for System.Text.Json from a JSON sample: PascalCase properties with [JsonPropertyName] attributes, int/long/double/bool/string, List<T>, and a separate class for every nested object. Fields that can be null or are missing from some elements are marked T?; the code compiles without warnings under #nullable enable.
📘 Common mistakes · Worked exampleGenerates C# classes for System.Text.Json from a JSON sample: PascalCase properties with [JsonPropertyName] attributes, int/long/double/bool/string, List<T>, and a separate class for every nested object. Fields that can be null or are missing from some elements are marked T?; the code compiles without warnings under #nullable enable.
The result is not exact or binding and is for information only; it is not an official document and cannot be used in official procedures. Confirm it with the competent authority or a professional before acting; no liability is accepted for losses arising from its use.
Last reviewed: · Methodology and sources
How is it calculated?
Generates C# classes for System.Text.Json from a JSON sample: PascalCase properties with [JsonPropertyName] attributes, int/long/double/bool/string, List<T>, and a separate class for every nested object. Fields that can be null or are missing from some elements are marked T?; the code compiles without warnings under #nullable enable.
Inputs
| Value | Unit | Example |
|---|---|---|
| JSON | — | {"id":1,"user_name":"Ada","email":"ada@example.com","score":9.5,"active":true,"tags":["a","b"],"address":{"city":"Berlin","zip":null},"orders":[{"order_id":7,"paid":true},{"order_id":8,"note":"gift"}]} |
| Root class name | — | Root |
What is this tool?
JSON to C# Class Converter helps developers with encoding, encryption and text processing. Generates C# classes for System.Text.Json from a JSON sample: PascalCase properties with [JsonPropertyName] attributes, int/long/double/bool/string, List<T>, and a separate class for every nested object. Fields that can be null or are missing from some elements are marked T?; the code compiles without warnings under #nullable enable.
Common mistakes
- Deleting the attributes and expecting names to match on their own. System.Text.Json is case-sensitive by default; html_url does not match HtmlUrl and the property silently stays empty.
- Relying on a string property never being null. Nullability annotations belong to compile time; with default settings a JSON null is assigned to a string property, and the first use may throw a NullReferenceException.
- Reading the initialisers as "this field is required". = ""; and = new(); only silence a compiler warning; nothing fails when the field is absent. Use required or [JsonRequired] to enforce presence.
- Leaving money amounts as double. The tool writes double for every decimal number, and binary floating point cannot represent values such as 0.1 exactly. Change amount fields to decimal by hand.
- Trusting classes generated from a single record. With one element in an array no field becomes T?; the tool can only notice that a field is sometimes missing when it sees several records.
- Leaving object? and List<object> lines as they are. They only say that null was all the tool saw, or that the array was empty or mixed; find out the real type and write it in.
- Reading integers that do not fit in a long as double. Most integers above 9223372036854775807 cannot be held exactly in a double; make such fields decimal or string.
📘 JSON to C# Classes: JsonPropertyName and Nullable Reference Types →
Sources
- Microsoft Learn: How to customize property names and values with System.Text.Json ([JsonPropertyName], naming policies) ↗
- Microsoft Learn: JsonPropertyNameAttribute Class (API reference) ↗
- Microsoft Learn: Nullable reference types (C#) ↗
- Microsoft Learn: Respect nullable annotations (System.Text.Json, RespectNullableAnnotations) ↗
Key terms
Frequently Asked Questions
+JSON to C# Class Converter — how is it calculated?
Generates C# classes for System.Text.Json from a JSON sample: PascalCase properties with [JsonPropertyName] attributes, int/long/double/bool/string, List<T>, and a separate class for every nested object. Fields that can be null or are missing from some elements are marked T?; the code compiles without warnings under #nullable enable.
+Which values are required?
JSON, Root class name.
+Is my data stored?
No. All calculations run in your browser; the values you enter are never sent to or stored on a server. If you press “Save”, the calculation stays only in your own browser and you can delete it at any time.
+Is it free?
Yes, all tools are free and require no sign-up.
Similar tools
Popular Tools
Free Calculators in One Place
Tax, finance, health, math and more — 500+ tools, all in one place.