JSON en C#

System.Text.Json es la biblioteca JSON moderna de C#.

Puntos clave

System.Text.Json es la biblioteca JSON moderna de C#.

Analizar JSON

using System.Text.Json;
User user = JsonSerializer.Deserialize<User>(text);

Convertir a cadena

string text = JsonSerializer.Serialize(user, new JsonSerializerOptions { WriteIndented = true });

Validar JSON

try {
  using JsonDocument doc = JsonDocument.Parse(text);
} catch (JsonException ex) {
  Console.WriteLine(ex.Message);
}