Sujets C# importants

JSON Serialization

System.Text.Json is the built-in high-performance JSON API for modern .NET.

How it works

Convert strongly typed objects to and from JSON.

Serialize converts a record into JSON. Deserialize recreates the typed value and nullable handling covers malformed or empty input.

Runnable C# example

C#
Run code →
Program.cs
using System;
using System.Text.Json;

record Product(string Name, decimal Price);

class Program
{
    static void Main()
    {
        var json = JsonSerializer.Serialize(new Product("Book", 12.5m));
        var product = JsonSerializer.Deserialize<Product>(json);
        Console.WriteLine($"{product?.Name}: {product?.Price}");
    }
}
Expected output
Book: 12.5

Practice with the debugger

Set a breakpoint on an important assignment or condition, click Debug, and inspect the local values before stepping to the next line.