using System.Collections;
using System.Collections.Generic;
using System.Text.Json.Serialization;
public static void Test()
var dictionary = new Dictionary<string, object>()
{"Key3", new Dictionary<string, object>(){ {"Key4", 123}}}
var serialized = JsonSerializer.Serialize(dictionary, new JsonSerializerOptions()
PropertyNamingPolicy = JsonNamingPolicy.CamelCase,
DictionaryKeyPolicy = JsonNamingPolicy.CamelCase,
Console.WriteLine(serialized);
Assert.AreEqual(@"{""key1"":5,""key2"":""aaa"",""key3"":{""key4"":123}}", serialized);
public static void Main()
Console.WriteLine("Environment version: {0} ({1})", System.Runtime.InteropServices.RuntimeInformation.FrameworkDescription , GetNetCoreVersion());
Console.WriteLine("System.Text.Json version: " + typeof(JsonSerializer).Assembly.FullName);
Console.WriteLine("Failed with unhandled exception: ");
public static string GetNetCoreVersion()
var assembly = typeof(System.Runtime.GCSettings).GetTypeInfo().Assembly;
var assemblyPath = assembly.Location.Split(new[] { '/', '\\' }, StringSplitOptions.RemoveEmptyEntries);
int netCoreAppIndex = Array.IndexOf(assemblyPath, "Microsoft.NETCore.App");
if (netCoreAppIndex > 0 && netCoreAppIndex < assemblyPath.Length - 2)
return assemblyPath[netCoreAppIndex + 1];