Skip to main content
chain
C#
JSON to C# error
⌃⏎ run · ⎋ clear · / focus input
// about this tool

JSON to C# Online

Updated 2026-10-24

Convert JSON to C# online for free. Paste a JSON object or array and SnapTools generates immutable C# records, adding System.Text.Json's JsonPropertyName attribute wherever a JSON key doesn't already match its PascalCase property name. Everything happens in your browser, so the JSON is never uploaded.

Paste an array rather than a single object and any key missing from at least one element gets marked nullable, so the generated record matches what your API actually returns across many responses rather than just the shape of its first sample.

// how to use

  1. 1 Paste your JSON; an array of objects lets optional fields be detected.
  2. 2 Set the root name; nested objects become their own records.
  3. 3 Copy the records into your project; the using directives you need are included.

// examples

A flat object
Input
{"user_id": 7, "name": "Ada"}
Output
public record Root with a UserId property carrying [JsonPropertyName("user_id")]
An optional field
Input
[{"id": 1}, {"id": 2, "note": "rush"}]
Output
Note becomes string? (nullable, because it is missing from one element)
A nested object
Input
{"address": {"city": "London"}}
Output
A separate Address record, referenced from the root

// common uses

Turning an API response into DTOs without hand-writing them Getting System.Text.Json binding right for snake_case payloads Scaffolding models for a new integration Checking which fields an external API always returns

// faq

Why does every renamed property get a JsonPropertyName attribute?
Because System.Text.Json will not bind a snake_case or kebab-case JSON key to a PascalCase property on its own; without the attribute the property silently stays null. It is added wherever the C# name differs from the JSON key.
Records or classes?
Records, with init-friendly properties. They are the modern default for DTOs, give you value equality for free, and are a smaller edit to turn into a class than the other way round.
Why are some types nullable?
A key missing from at least one element of the array you pasted is marked nullable, so nullable reference types and the compiler agree with reality. Paste a single object and nothing is marked nullable.
Do I need Newtonsoft.Json?
No. The output targets System.Text.Json, which ships with .NET. If you use Newtonsoft, swap JsonPropertyName for JsonProperty.
Is my JSON uploaded?
No. The conversion runs in your browser, so the JSON never leaves your machine.

Use this via API

Get a free API key →
curl -X POST https://thesnaptools.com/api/v1/tools/json-to-csharp \
  -H "Authorization: Bearer YOUR_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{"json":"{\"user_id\": 7, \"name\": \"Ada\"}"}'