/

JSON to C#

Processed Client Side

Generate C# classes or records from a JSON sample, with System.Text.Json or Newtonsoft attributes and nullable value types inferred.

JSON · 14 lines
14 lines · 216 chars
Length: 216Lines: 14Size: 216 BytesCursor: 1:1
C#
C#
csharpLength: 921Lines: 45Size: 921 BytesCursor: 1:1

Bookmark this tool now — skip the search next time you need it.

About JSON to C#

This tool runs entirely in your browser. Whatever you paste is processed on your own device and is never uploaded, logged, or sent to any server.

The JSON to C# converter turns a sample JSON payload into ready-to-use C# classes or records, so you can deserialize an API response into real types instead of digging through a dictionary. It walks the whole document: nested objects become their own types, arrays become List<T>, and numbers are mapped to int, long, or double based on the values it actually sees. Keys are converted to PascalCase properties and given the matching [JsonPropertyName] or [JsonProperty] attribute so the original wire names still bind. Choose classes or records, System.Text.Json or Newtonsoft, and an optional namespace, and paste the result straight into your project.

Key features

  • Classes or records — records give you a concise immutable model, classes the familiar mutable one
  • Attributes for System.Text.Json ([JsonPropertyName]) or Newtonsoft ([JsonProperty]), or none at all
  • Optional file-scoped namespace declaration, with using directives added only when they are needed
  • Nested objects promoted to their own sibling types, named from the key that held them
  • Arrays of objects merged into one type: every element is inspected, and a field missing from some of them is marked nullable
  • Numeric types chosen from the data — int, long when a value exceeds Int32 range, and double when any value is fractional
  • snake_case, kebab-case, and camelCase keys converted to PascalCase properties, with collisions resolved so the output compiles
  • Nullable annotations applied to value types only (int?, bool?), so the code builds whether or not nullable reference types are enabled
  • Syntax-highlighted C# output and a one-click copy, generated entirely in your browser

How to use it

  1. Paste a representative JSON response into the input pane.
  2. Set the root class name, and a namespace if you want one emitted.
  3. Choose class or record, and the attribute style matching your serializer.
  4. Press Convert and read the generated types.
  5. Copy the code into your project and deserialize with JsonSerializer.Deserialize<Root>(json).

Tips & common mistakes

  • Paste the richest sample you have. The generator can only type what it sees — a field that is null in your one sample becomes object, and an array that is empty becomes List<object>.
  • For arrays, include elements that differ from each other. Every element is merged into one class, so optional fields are detected as nullable rather than being missed entirely.
  • Check the numeric types before shipping. An id that happens to fit in Int32 today becomes int, so if the API can return larger values, widen it to long by hand.
  • Records suit response models you never mutate and give you value equality for free. Stay with classes if you deserialize into an existing object graph or need parameterless construction.
  • Attributes matter more than they look. Without them, System.Text.Json is case-sensitive by default and a user_name key will silently leave UserName null.
  • A mixed-type field — sometimes a string, sometimes a number — has no single static type and comes out as object. That is usually worth fixing in the API rather than in the model.
  • Working in Java instead? The JSON to Java converter uses the same analysis and emits POJOs, records, or Lombok classes with Jackson annotations.

Related tools

Browse all 24 JSON tools

Frequently asked questions

10

Paste a sample JSON response, set the root class name, choose class or record and your attribute style, then press Convert. The generated types appear ready to copy into your project.

Records suit response models you never mutate and give you value equality and concise syntax. Classes are the safer choice when you deserialize into an existing object graph or need parameterless construction.

[JsonPropertyName] for System.Text.Json, [JsonProperty] for Newtonsoft, or none. Keep them on — System.Text.Json is case-sensitive by default, so a user_name key would otherwise leave UserName null.

Each becomes its own class, named from the key that held it and emitted as a sibling type inside the namespace, since C# allows several public types in one file.

Every element is inspected and merged into a single class, so slightly different shapes still produce one type. A field missing from some elements is marked nullable rather than dropped.

From the values it sees: int for integers, long when a value falls outside Int32 range, and double when any value is fractional. Widen a type by hand if the API can return larger values than your sample.

Either the key was null in every sample, or it held different types across samples. Neither can be expressed as one static type, so it falls back to object.

Nullability is annotated on value types only — int?, bool? — while reference types are left bare. That way the generated code compiles whether or not your project enables nullable reference types.

No. The whole analysis runs in your browser, which matters when the sample is a real API response containing customer data or tokens.

The JSON to Java converter uses the same analysis and emits POJOs, Lombok classes, or records with Jackson annotations.