JSON to C# class
Paste JSON and get C# classes for it below, as you type: properties in PascalCase, each reading its JSON key, for System.Text.Json.
Names that match
System.Text.Json matches names exactly unless told otherwise, so a property whose key is written another way (firstName, first_name) gets [JsonPropertyName("…")] with the key. A property can't have its class's name, so one that would is called …Value.
The types
int for whole numbers in 32 bits, long beyond and decimal past 64 bits; double for decimals; List<T>, and Dictionary<string, T> for objects keyed by ids or dates; object for values of mixed kinds. Values that may be null or missing are nullable (int?, string?).
Types from sample data
Every item of a list, and every value of JSON Lines, is a sample of the same type: a key that some lack is optional, a value that is sometimes null is nullable, whole numbers mixed with decimals are decimals, and objects with the same keys share one type, named after the key they are under ("line_items" holds LineItem). An object whose keys are ids or dates, such as {"1001": {…}, "1002": {…}}, is a map. YAML, TOML, CSV and the other formats work too: pick their language above the editor.
Or the data as a Dictionary
Data writes the JSON as nested Dictionary<string, object?> and List<object?> initializers, for a test or a quick script.
Copy, download or switch
The C# follows your typing, and a mistake in the JSON is pointed out first, with its line and column. Copy or Download (a .cs file) take it as it is. Above the code, switch between Types and Data, or pick another language; the Convert menu's Code item opens the one you picked last.
Private: nothing is uploaded
Formatting, checking and comparing all happen in your browser. Your documents are saved in the browser's own storage on this computer, not on a server, so they never leave your device.
With your permission, we count anonymous visits (which pages and tools are used), never what you type. See Privacy.
Questions
How do I read the JSON into the classes?
JsonSerializer.Deserialize<Root>(json); for a list at the top, JsonSerializer.Deserialize<List<Item>>(json).
Do the classes work with Newtonsoft.Json?
Yes. Newtonsoft ignores [JsonPropertyName] but matches names regardless of case, so firstName still reads into FirstName; for a key such as first_name, add [JsonProperty("first_name")].
Is my data uploaded anywhere?
Your documents aren't: everything runs in your browser, and they are saved on your computer, in the browser's storage for this site. With your permission we count anonymous visits, never their content.
More tools
- Formatter & Converter for JSON, YAML, XML, SQL
- JSON to TypeScript – Interfaces from JSON
- JSON to Go Struct Converter
- JSON to Java Class & Record Converter
- JSON to Python Dataclass, Pydantic & Dict
- JSON to Kotlin Data Class Converter
- JSON to Dart Model with fromJson & toJson
- JSON to Swift Codable Struct Converter
- JSON to Rust Struct Converter (serde)
- Free Online Diagram Maker & Editor
- Crypto Tools: Passwords, Keys, Hashes & JWTs
- Timestamp, Cron, Regex & UUID Utilities