Convert C# to JSON
Mock data, snippets
or JSON Schema.
Generate mock JSON from a C# class or record, get System.Text.Json and Newtonsoft serialization snippets, or convert your class to a JSON Schema. Three modes, one tool.
Each mode covers a different intent — choose the one that fits your situation.
Paste a C# class, record or interface and get a realistic JSON object with example values for each property. Works with auto-properties, nullable types and List<T>. Useful for Postman collections, Swagger examples and unit test fixtures without running .NET.
public int Id { get; set; }
public string? Name { get; set; }
public bool IsActive { get; set; }
{"id":1,"name":"Alice",
"isActive":true}
Get ready-to-run C# code for serializing objects to JSON with System.Text.Json or Newtonsoft.Json. Covers basic, pretty-print, List<T>, file output, ASP.NET Core controller and HttpClient request body — with using statements included.
using System.Text.Json;
var json = JsonSerializer
.Serialize(obj, new
JsonSerializerOptions {
WriteIndented = true });
Convert a C# class definition to a JSON Schema Draft-07 or 2020-12 document. C# types are mapped to JSON Schema keywords — nullable properties (type?) are excluded from required, List<T> becomes array with item type, and nested classes become $defs references.
{"type":"object",
"required":["id"],
"properties":{
"id":{"type":"integer"},
"name":{"type":"string"}
}}
The key differences between the two C# serialization approaches.
| System.Text.Json | Newtonsoft.Json | |
|---|---|---|
| NuGet | Built-in (.NET Core 3.0+) | Install-Package Newtonsoft.Json |
| Serialize | JsonSerializer.Serialize(obj) | JsonConvert.SerializeObject(obj) |
| Pretty print | new JsonSerializerOptions { WriteIndented = true } | Formatting.Indented |
| Key naming | [JsonPropertyName("key")] | [JsonProperty("key")] |
| Ignore null | DefaultIgnoreCondition = WhenWritingNull | NullValueHandling.Ignore |
| Best for | .NET 6/7/8/9 — faster, no dep | Legacy .NET Fw, complex scenarios |
ASP.NET Core uses System.Text.Json by default — when you return a C# object from a controller action, it is automatically serialized to JSON. For manual serialization, logging or caching use JsonSerializer.Serialize(obj). Mode 2 gives you the exact snippet for your scenario.
API documentation tools like Swagger/OpenAPI and Postman collections need JSON examples for every endpoint. Mode 1 generates a realistic sample from your request/response class without instantiating the class or running the API — paste directly into Swagger example annotations.
Sending JSON in an HttpClient POST request requires serializing the request object. Mode 2 gives you the complete HttpClient snippet using JsonContent.Create(obj) (.NET 5+) or StringContent with manual serialization for older versions.
C# type safety only applies at compile time. For runtime validation of incoming API payloads — from external services, message queues or file uploads — you need a JSON Schema. Mode 3 converts your request model class to a Draft-07 schema for use with NJsonSchema or System.Text.Json's validation extensions.
C# parsed in your
browser. No compiler needed.
The mock JSON and JSON Schema modes use a property-level regex parser — no need to compile or run .NET. The parser extracts property names and types from class and record definitions, handles nullable annotations (type?) and List<T> generics correctly. The serialization snippets are generated statically — no API call.
The JSON Schema output maps nullable C# properties to optional schema fields — types marked with ? are excluded from the required array, matching the runtime behaviour of JsonSerializer when DeserializeAsync encounters a missing property.
