JSON to C# Class

Paste JSON and get C# classes or records, with the right attributes for System.Text.Json or Newtonsoft.Json.

FreeNo sign-upPrivate — runs in your browser
0Classes
0Fields
0Lines

How to use the JSON to C# Converter

  1. Paste JSONPaste an API response or any JSON object, or open a .json file.
  2. Choose the optionsPick attributes for System.Text.Json or Newtonsoft.Json, and classes or immutable records.
  3. Copy the codePaste it into a .cs file and deserialize with JsonSerializer.Deserialize<Root>(json).

Example

"is_active": true becomes [JsonPropertyName("is_active")] public bool IsActive { get; set; }.

"coupon" is null in one sample order, so it becomes string? Coupon. Lists start as new() so they are never null.

Frequently asked questions

Which .NET version does this target?

The code uses nullable reference types (string?) and target-typed new(), which need C# 9 / .NET 5 or later. Remove the ? marks for older projects.

Why long and double?

Whole numbers become long so large IDs fit, and decimals become double. Use decimal for money if you need exact arithmetic.

Do I need the attributes?

Only if your JSON keys differ from the C# names (for example snake_case keys). System.Text.Json can also be told to ignore case with PropertyNameCaseInsensitive = true.

Popular posts from this blog

Character Counter

Speech to Text Online

Keyboard Tester