.NET · Free · No signup

JSON to C# Class Converter

Paste any JSON and get ready-to-use C# classes or records. Nested objects, lists, nullable types, dates and GUIDs are detected, and you can choose System.Text.Json or Newtonsoft.Json attributes. Everything runs in your browser.

Paste your JSON

Options

C# code

    When you need a JSON to C# converter

    Almost every .NET project reads JSON at some point: responses from a third-party API, webhook payloads, configuration files or data exported from another system. Writing the matching C# classes by hand is slow and easy to get wrong, especially when the JSON is deeply nested. A converter builds the first version for you in seconds, so you can spend your time on the logic that uses the data.

    How to use the generated code

    1. Paste a representative JSON sample into the box. A sample that includes optional fields gives better results.
    2. Choose class or record, the attribute style your project uses, and whether you want nullable reference types.
    3. Copy the code into a new .cs file in your project.
    4. Deserialize the JSON into the root class:
    var options = new JsonSerializerOptions { PropertyNameCaseInsensitive = true };
        var data = JsonSerializer.Deserialize<Root>(json, options);

    If the JSON root is an array, deserialize to List<Root> instead.

    How the converter decides on types

    • Numbers: whole numbers become int (or long when they are large), numbers with a fraction become double, or decimal if you choose it.
    • Dates and GUIDs: strings that look like ISO 8601 dates become DateTime, and strings in GUID format become Guid.
    • Lists: items are merged into a single class. Fields missing from some items become nullable.
    • Names: keys such as first_name become FirstName, and an attribute keeps the link to the original JSON key.

    Check the result before you rely on it

    The generated code is a strong starting point, not a finished model. A single sample cannot show every possible value, so review the types it chose. Fields that hold money are usually better as decimal. A field that is always null in your sample will be typed as object because the real type is unknown. Rename properties to match your conventions, and add validation where your application needs it.

    Frequently asked questions

    How do I convert JSON to a C# class?

    Paste your JSON, choose your options, and copy the generated code into a .cs file. Then deserialize with JsonSerializer.Deserialize<Root>(json) for System.Text.Json or JsonConvert.DeserializeObject<Root>(json) for Newtonsoft.Json.

    Should I use System.Text.Json or Newtonsoft.Json?

    System.Text.Json is built into modern .NET and is a good default for new projects. Newtonsoft.Json is still very common and has more features, so choose it if your project already uses it.

    Why do some properties end with a question mark?

    A question mark marks a nullable type. Value types such as int and DateTime get one when the JSON contains null or the field is missing in some objects. Reference types such as string get one when nullable reference types are enabled.

    How are number types chosen?

    Whole numbers become int, or long when they are too large for int. Numbers with a fraction become double, or decimal if you tick that option, which is a better choice for money. Note that a value written as 10.0 is read as a whole number by the browser's JSON parser, so check such fields by hand.

    What happens when objects in a list have different fields?

    They are merged into one class. A field that is missing from some objects is marked nullable, and a field that holds different types is typed as object so you can decide how to handle it.

    Should I generate a class or a record?

    Records are a good fit for read-only data transfer objects, and modern System.Text.Json can fill positional records through their constructor. Use a class if you need to change values after loading them.

    Is my JSON uploaded anywhere?

    No. The converter runs entirely in your browser with JavaScript. What you paste is not uploaded or stored by us.

    Need a custom .NET application built?

    Our team builds .NET 8 web applications with SQL Server, authentication and admin dashboards, tailored to your workflow.