Mock JSON · STJ · Newtonsoft · JSON Schema — 3 modes

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.

Your data never leaves your browser
C# class → mock JSON
JsonSerializer & JsonConvert snippets
C# class → JSON Schema
Always free
C# to JSON — 3 modes   100% client-side
C# class input
  Ready

      
Three ways to convert C# to JSON

Each mode covers a different intent — choose the one that fits your situation.

Mode 1 — Mock JSON

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.

Input
public int Id { get; set; }
public string? Name { get; set; }
public bool IsActive { get; set; }
Output
{"id":1,"name":"Alice",
 "isActive":true}
Mode 2 — Serialization snippets

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.

STJ output
using System.Text.Json;
var json = JsonSerializer
  .Serialize(obj, new
  JsonSerializerOptions {
    WriteIndented = true });
Mode 3 — JSON Schema

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.

Output
{"type":"object",
 "required":["id"],
 "properties":{
   "id":{"type":"integer"},
   "name":{"type":"string"}
 }}
JsonSerializer vs JsonConvert — quick reference

The key differences between the two C# serialization approaches.

System.Text.JsonNewtonsoft.Json
NuGetBuilt-in (.NET Core 3.0+)Install-Package Newtonsoft.Json
SerializeJsonSerializer.Serialize(obj)JsonConvert.SerializeObject(obj)
Pretty printnew JsonSerializerOptions { WriteIndented = true }Formatting.Indented
Key naming[JsonPropertyName("key")][JsonProperty("key")]
Ignore nullDefaultIgnoreCondition = WhenWritingNullNullValueHandling.Ignore
Best for.NET 6/7/8/9 — faster, no depLegacy .NET Fw, complex scenarios
When do you need C# to JSON?
ASP.NET Core serialization

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.

Postman and Swagger examples

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.

HttpClient request bodies

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.

Runtime validation

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.

Popular searches
csharp to json c# to json c# object to json c# serialize to json c# class to json c# to json string c# object to json string serialize c# object to json c# to json online jsonserializer c# c# to json schema c# class to json schema c# model to json

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.

Nullable-aware parser
Properties marked with ? are correctly handled — excluded from required in JSON Schema and given nullable mock values in Mode 1.
STJ and Newtonsoft
Both libraries covered with complete using statements, NuGet dependencies and 6 real-world scenarios — copy and paste directly.
JSON Schema from class
C# class → Draft-07 JSON Schema for runtime validation — the complement to the JSON Schema → C# direction in json-to-csharp.
47 tools, always free
No file size limits, no watermarks, no account. Funded by non-intrusive display advertising only.
Frequently asked questions
Common questions about converting C# classes to JSON.
How do I serialize a C# object to JSON?
Use System.Text.Json (built into .NET Core 3.0+): string json = JsonSerializer.Serialize(myObject). For Newtonsoft: string json = JsonConvert.SerializeObject(myObject). Select the Serialization Snippets mode for the complete code with using statements and options.
How do I pretty-print JSON in C#?
System.Text.Json: JsonSerializer.Serialize(obj, new JsonSerializerOptions { WriteIndented = true }). Newtonsoft: JsonConvert.SerializeObject(obj, Formatting.Indented). Both produce indented output with 2-space indentation by default.
How do I send a C# object as JSON in an HttpClient POST?
For .NET 5+: var response = await client.PostAsJsonAsync("/api/endpoint", myObject). For older versions: var content = new StringContent(JsonSerializer.Serialize(myObject), Encoding.UTF8, "application/json"); var response = await client.PostAsync("/api/endpoint", content). Select the HttpClient scenario in Mode 2 for the complete snippet.
How do I convert a C# class to JSON Schema?
Select the JSON Schema mode, paste your C# class, and click Generate. C# types are mapped to JSON Schema: string → type: string, int/long → type: integer, double → type: number, bool → type: boolean, List<T> → type: array. Nullable properties (type?) are excluded from required.
Is the C# to JSON converter free?
Yes, completely free. No file size limits, no account required. JSONshift is funded by non-intrusive display advertising.
Go up