format · validate · convert · runs locally

Parse JSON in C#

How to parse a JSON string into an object and serialize (stringify) an object back to JSON in C#. System.Text.Json ships with .NET Core 3.0+; Newtonsoft.Json is the classic alternative. Need to clean up the JSON first? Use the formatter & validator.

Parse JSON (string → object)

using System.Text.Json;
var obj = JsonSerializer.Deserialize<Dictionary<string, object>>(text);

Stringify (object → JSON string)

var text = JsonSerializer.Serialize(obj,
    new JsonSerializerOptions { WriteIndented = true });

Frequently asked questions

How do I parse JSON in C#?

System.Text.Json ships with .NET Core 3.0+; Newtonsoft.Json is the classic alternative. Parse with the snippet above; the result is a native object/map you can read.

How do I pretty-print JSON in C#?

Use the stringify snippet above with indentation, or paste your JSON into the formatter on this page.