using System.Collections;
using System.Collections.Generic;
using System.Runtime.Serialization.Formatters;
using System.ComponentModel.DataAnnotations;
using System.Globalization;
using System.Text.Json.Serialization;
public long Id { get; set; }
[System.Text.Json.Serialization.JsonExtensionDataAttribute]
public IDictionary<string, object> ExtensionData { get; set; } = new TestDictionary();
public class TestDictionary : Dictionary<string, object>, IDictionary, IDictionary<string, object>
public new void Add(string key, object value)
throw new NotImplementedException();
public new object this[string key]
throw new NotImplementedException();
Console.WriteLine(string.Format("value type {0}", value.GetType()));
throw new NotImplementedException();
public static void Test()
var existingUserIds = JsonSerializer.Deserialize<List<UserObject>>(GetExistingUsersJson()).Select(u => u.Id).ToHashSet();
Console.Write("\nExisting user ids:");
Console.WriteLine(JsonSerializer.Serialize(existingUserIds));
var rawJsonDownload = GetRawJsonDownload();
var users = JsonSerializer.Deserialize<List<UserObject>>(rawJsonDownload);
users.RemoveAll(u => existingUserIds.Contains(u.Id));
var newJson = JsonSerializer.Serialize(users, new JsonSerializerOptions { WriteIndented = true });
Console.WriteLine("\nNew users only: ");
Console.WriteLine(newJson);
static string GetRawJsonDownload()
""address"" : { ""Line1"" : ""line 1"", ""Line2"" : ""line 2""},
""discount"" : 123.1212121121212121
""address"" : { ""Line1"" : ""line 1"", ""Line2"" : ""line 2""},
""discount"" : 22.220000000000000000000
""address"" : { ""Line1"" : ""line 1"", ""Line2"" : ""line 2""},
""discount"" : 123.1212121121212121
static string GetExistingUsersJson()
""address"" : { ""Line1"" : ""line 1"", ""Line2"" : ""line 2""},
""discount"" : 10.1100000000000000000000000
""address"" : { ""Line1"" : ""line 1"", ""Line2"" : ""line 2""},
""discount"" : 123.1212121121212121
""address"" : { ""Line1"" : ""line 1"", ""Line2"" : ""line 2""},
""discount"" : 123.1212121121212121
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.CodeBase.Split(new[] { '/', '\\' }, StringSplitOptions.RemoveEmptyEntries);
int netCoreAppIndex = Array.IndexOf(assemblyPath, "Microsoft.NETCore.App");
if (netCoreAppIndex > 0 && netCoreAppIndex < assemblyPath.Length - 2)
return assemblyPath[netCoreAppIndex + 1];