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; }
public static void Test()
var newJson = TestMethod();
Console.WriteLine("\nNew users only: ");
Console.WriteLine(newJson());
public static Func<string> TestMethod()
var existingUserIds = JsonSerializer.Deserialize<List<UserObject>>(GetExistingUsersJson()).Select(u => u.Id).ToHashSet();
Console.Write("\nExisting user ids:");
Console.WriteLine(JsonSerializer.Serialize(existingUserIds));
Predicate<long> shouldSkip = i => existingUserIds.Contains(i);
var rawJsonDownload = GetRawJsonDownload();
var users = JsonSerializer.Deserialize<List<UserObject>>(rawJsonDownload);
users.RemoveAll(u => shouldSkip(u.Id));
public static Func<string> Json<T>(T obj)
return () => JsonSerializer.Serialize(obj, new JsonSerializerOptions { WriteIndented = true });
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];