Serialization turns an object in memory into text you can send or store. Deserialization turns that text back into an object. In C# the default tool for JSON is System.Text.Json, which shipped with .NET Core 3.0 and is now the one to reach for. Newtonsoft.Json is still everywhere, still excellent, and still the answer when you need something System.Text.Json does not do yet.

Most JSON problems in C# come down to naming. C# properties are PascalCase, most JSON is camelCase, and almost everything in the first section below exists to close that gap.

JSON first below, then XML and YAML.

Naming, Ordering and What Gets Included

The part that causes the most trouble: making the JSON look the way the other side expects.

XML and YAML

The same jobs in the other two formats, including converting between JSON and XML.

Deserializing JSON to Objects

JSON in, object out, including the case where you do not have a class to put it in.

Serializing Objects to JSON

Object in, JSON out.

Reading and Changing JSON Directly

Sometimes you do not want a class at all, you just want a value out of a document.

Where to Go Next

JSON usually arrives over the wire or out of a file:

Write the class you want first and let the serializer complain. Shaping a class around a setting you have not needed yet costs more than fixing it once you have.