Working with JSON

Learn how to use the System.Text.Json namespace to serialize C# objects into JSON format, deserialize JSON back into objects, and seamlessly read and write JSON files asynchronously.

JSON (JavaScript Object Notation) is the industry standard format for data exchange, configuration files, and web APIs. It is a lightweight, text-based format that is easy for humans to read and write, and easy for machines to parse and generate.

Modern .NET provides the System.Text.Json namespace. This built-in library delivers high-performance JSON manipulation without relying on third-party packages. The two primary operations we perform with JSON are serialization and deserialization.

Serialization (C# object to JSON)

Serialization is the process of converting a .NET object (like a class or struct) into a JSON string. We use the JsonSerializer.Serialize method to convert a C# object into a JSON string.