using System.Collections;
using System.Collections.Generic;
using System.Threading.Tasks;
using System.Text.Json.Serialization;
public static async Task Test()
var myClassFromNewtonsoft = Newtonsoft.Json.JsonConvert.DeserializeObject<MyClass>(json);
Console.WriteLine($"Successfully deserialized JSON {json} into {typeof(MyClass)} using Newtonsoft, value {(myClassFromNewtonsoft == null ? "is null" : " is {myClassFromNewtonsoft}")}.");
var stream = new MemoryStream(Encoding.UTF8.GetBytes(json));
var myClass = await JsonSerializer.DeserializeAsync<MyClass>(stream, new JsonSerializerOptions
PropertyNamingPolicy = JsonNamingPolicy.CamelCase
Console.WriteLine($"Successfully deserialized JSON {json} into {typeof(MyClass)} using System.Text.Json, value {(myClass == null ? "is null" : " is {myClass}")}.");
private static async Task<T> GetWithSystemTextJson<T>(string uri, HttpClient httpClient)
using var httpResponse = await httpClient.GetAsync(uri, HttpCompletionOption.ResponseHeadersRead);
httpResponse.EnsureSuccessStatusCode();
var stream = await httpResponse.Content.ReadAsStreamAsync();
return await System.Text.Json.JsonSerializer.DeserializeAsync<T>(stream,
new System.Text.Json.JsonSerializerOptions
PropertyNameCaseInsensitive = true
public static async Task Main(string[] args)
Console.WriteLine("Environment version: {0} ({1})", System.Runtime.InteropServices.RuntimeInformation.FrameworkDescription , Environment.Version);
Console.WriteLine("{0} version: {1}", typeof(JsonSerializer).Assembly.GetName().Name, typeof(JsonSerializer).Assembly.FullName);
Console.WriteLine("Failed with unhandled exception: ");