using System.Collections;
using System.Collections.Generic;
using System.Runtime.Serialization.Formatters;
using System.ComponentModel.DataAnnotations;
using System.Globalization;
using System.Text.Json.Serialization;
using System.Text.Json.Nodes;
using System.Net.Http.Json;
using System.Threading.Tasks;
public static void Test()
var newJson = TestMethod();
Console.WriteLine("\nNew users only: ");
Console.WriteLine(newJson());
var array = JsonSerializer.Deserialize<JsonArray>("[0]");
Assert.AreEqual(array.Count, 1);
static async Task<JsonNode> TestHttpclient()
var httpClient = new HttpClient();
var root = await httpClient.GetFromJsonAsync<JsonArray>("WEB API CALL");
public static Func<string> TestMethod()
ICollection<long> existingUserIds;
using(var existingUsersDocument = JsonDocument.Parse(GetExistingUsersJson()))
existingUserIds = existingUsersDocument.RootElement.EnumerateArray().Select(u => u.GetProperty("id").GetInt64()).ToHashSet();
Console.Write("\nExisting user ids:");
Console.WriteLine(JsonSerializer.Serialize(existingUserIds));
Predicate<long> shouldSkip = i => existingUserIds.Contains(i);
var rawJsonDownload = GetRawJsonDownload();
var root = JsonNode.Parse(rawJsonDownload).AsArray();
for (int i = root.Count - 1; i >= 0; i--)
if (shouldSkip(root[i].AsObject()["id"].GetValue<long>()))
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];