C# Class to JSON Schema Generator

Need JSON to C#?
JSON → C# Classes

C# code Input

Loading editor…

JSON Schema Output

Settings

Select which class or record should be treated as the root when generating the schema.

Parsing runs entirely in your browser. Your source never leaves the page.

Paste your C# DTOs to produce a JSON Schema instantly.

Supports classes, structs, records, annotations, nullable reference types, and generic collections.

How to convert C# classes and records to JSON Schema – step-by-step guide

This online C# class to JSON Schema converter helps you generate JSON Schema from real models (DTOs, structs, and classes) so you can validate payloads, share contracts, and generate mock JSON.

  1. Step 1 – Paste your C# source

    • Paste the models you want to document into the left editor.
    • Include referenced types in the same snippet so the schema can generate definitions.
    • Use the Sample button to load an example and see the expected input format.
  2. Step 2 – Select the Root class (if needed)

    • If multiple definitions are detected, choose the root that matches your API payload.
    • The output schema is built around the selected root and may include additional definitions for referenced types.
  3. Step 3 – Review the JSON Schema output

    • Check types, required vs. optional fields, and nested object/array structures.
    • Look for definitions and $ref when your models reference other models.
    • Copy or download the schema for validation, documentation, or schema-first development.
  4. Step 4 – Validate or generate mock JSON

    • Click Generate Mock Data to open the mock generator with your schema preloaded.
    • Validate real payloads against your schema to catch breaking changes early.
    • If you rely on advanced schema composition (for example anyOf/oneOf/allOf), verify the result with a full validator like Ajv.

Schema keyword support note

Generated schemas can include $ref and may be edited to include anyOf, oneOf, or allOf. For complex schemas, use a full JSON Schema validator and dereference before mock generation if needed.

Related JSON Schema & code generation tools

Use these tools to validate schemas, generate mock payloads, format JSON examples, and keep code and contracts in sync.

Frequently Asked Questions

Which C# constructs are supported?

The parser understands classes, structs, records (with primary constructors), auto-properties, backing fields, enums, and attributes such as JsonPropertyName, JsonProperty, and DataMember(Name=...). It respects nullable reference types, optional fields, collections, and dictionaries directly in the generated schema.

How are types mapped to JSON Schema?

Primitives such as string, bool, int/double/decimal, DateTime/DateOnly/Guid map to the closest schema type and format. Arrays, List<T>, IEnumerable<T>, Dictionary<TKey, TValue>, Nullable<T>, and T? are converted into array/object/optional schema constructs. Unrecognized symbols fall back to references when they match another class or enum.

Does it work with different C# versions and serializers?

Yes. Modern features like records, init-only setters, nullable reference types, System.Text.Json annotations, and classic Newtonsoft.Json attributes are handled. The tool runs completely in your browser, so you can safely paste proprietary DTOs or API contracts.

How can I generate mock JSON?

After the schema is created, click "Generate Mock Data" to open the Mock Generator with your schema preloaded. Configure locales, array counts, and optional fields to instantly produce realistic payloads for docs or tests.

Convert C# Classes to JSON Schema Online | JSONSwiss