How do I work with JSON in C#

C#, JSON, Newtonsoft.Json, System.Text.Json, Serialization, Deserialization, API Integration
Learn how to work with JSON in C# using popular libraries like Newtonsoft.Json and System.Text.Json for serialization and deserialization.
// Example of working with JSON in C# using System; using System.Text.Json; using System.Collections.Generic; public class Person { public string Name { get; set; } public int Age { get; set; } } class Program { static void Main() { // Creating a new Person object Person person = new Person { Name = "John Doe", Age = 30 }; // Serializing the object to JSON string json = JsonSerializer.Serialize(person); Console.WriteLine(json); // Output: {"Name":"John Doe","Age":30} // Deserializing the JSON back to a Person object Person deserializedPerson = JsonSerializer.Deserialize(json); Console.WriteLine($"Name: {deserializedPerson.Name}, Age: {deserializedPerson.Age}"); } }

C# JSON Newtonsoft.Json System.Text.Json Serialization Deserialization API Integration