JSON to C#
This JSON to C# tool generates C# model classes. It supports both the built-in System.Text.Json and Newtonsoft.Json annotation sets, a custom namespace and root class name, and capitalises property names automatically. Generation runs locally in your browser and API data is not uploaded.
How to use it
- 1
Paste your JSON
Paste a JSON response; nested objects become partial classes and arrays become typed array properties.
- 2
Choose framework and namespace
Pick System.Text.Json (the .NET Core default) or Newtonsoft.Json, and enter a namespace and root class name.
- 3
Copy the C# code
Copy the generated output and paste it into your Models folder to deserialise directly.
- 4
Use it in your project
Deserialise with JsonSerializer or JsonConvert according to the framework you chose.
Key features
Dual framework support
System.Text.Json uses the built-in JsonSerializer; Newtonsoft.Json emits [JsonProperty] attributes so older projects can adopt it directly.
Configurable namespace
Enter a namespace such as MyApp.Models and the generated code is wrapped accordingly.
C# naming normalisation
snake_case JSON keys become PascalCase property names, with serialisation attributes preserving the original mapping.
Nullable and collection types
Null fields and arrays are inferred as object / nullable types and strongly typed arrays, reducing boxing and manual conversion.
Partial classes
Generated classes use the partial keyword so you can add methods in another file without them being overwritten.
Types-only option
A toggle outputs just the class and property definitions without the using statements, namespace boilerplate and parsing sample.
Common errors & troubleshooting
- ! For .NET Core 3.0+ / .NET 5+ prefer System.Text.Json, which needs no extra NuGet package.
- ! Choose Newtonsoft.Json when you need compatibility with older WebForm or .NET Framework projects.
- ! The generated classes use partial, so you can extend a same-named partial class in another file without it being regenerated away.
- ! Non-ASCII property mappings are preserved through the serialisation attributes, so deserialisation is unaffected.
Frequently asked questions
Why are property names capitalised automatically?
The C# convention is PascalCase for properties, so the tool turns user_name into UserName and keeps the mapping to the original JSON key through a serialisation attribute, leaving deserialisation unaffected.
What is the "Types only" option for?
When ticked, only the class and property definitions are emitted, omitting the using statements, namespace boilerplate and deserialisation sample. Unticked, it produces a complete, runnable file with a parsing method.
Can an enum field generate an enum automatically?
A single sample cannot determine all possible values, so the tool does not risk emitting an enum. Paste samples covering every enum value (multi-sample input arrives in a later version) for more accurate inference.
Is my JSON uploaded?
No. Generation runs locally in your browser.
Related tools
JSON to Java
Generate Java POJOs from JSON with fields, getters/setters and type inference. Choose Jackson, Lombok + Jackson or a plain POJO, and set a custom package name. Runs locally in a Web Worker.
JSON to Go
Generate Go structs from JSON with json tags. Nested objects become well-named sub-structs, with a custom package name and configurable omitempty style. Runs locally in your browser.
JSON to TypeScript
Generate TypeScript interface or type definitions from a sample JSON payload.
JSON Formatter
Format, beautify and validate JSON in your browser. Errors point to the exact line and column, and you can indent with 2 spaces, 4 spaces or a tab.