using System.Collections;
using System.Collections.Generic;
using System.Runtime.Serialization.Formatters;
using System.ComponentModel.DataAnnotations;
using System.Globalization;
using Newtonsoft.Json.Linq;
using Newtonsoft.Json.Converters;
using Newtonsoft.Json.Serialization;
private static IEnumerable<string> ParseJObject(JObject node)
HashSet<string> documentProperties = new HashSet<string>();
foreach (KeyValuePair<string, JToken> sub in node)
if (sub.Value.Type == JTokenType.Array)
if (sub.Value.First.Type == JTokenType.Object)
foreach (var innerNode in sub.Value.Children())
documentProperties.UnionWith(ParseJObject((JObject)innerNode));
documentProperties.Add(CreateDocumentProperty(sub.Value));
else if (sub.Value.Type == JTokenType.Object)
documentProperties.UnionWith(ParseJObject((JObject)sub.Value));
return documentProperties;
private static string CreateDocumentProperty(JToken subValue) => $"{subValue.Path}/new:{subValue[0]}/old:{subValue[1]}";
public static void Test()
var jToken = JToken.Parse("{\"lastName\":[\"Bab\",\"Beb\"],\"middleName\":[\"Cg\",\"seeg\"],\"contact\":{\"emailAddress\":[\"bab@example.com\",\"beb@example.com\"],\"addresses\":[{\"state\":[\"AL\",\"AZ\"]},{\"state\":[\"TN\",\"MO\"]}],}}");
var jContainer = jToken as JObject;
throw new JsonException("Input was not a container");
foreach (var item in ParseJObject(jContainer))
Assert.IsTrue(ParseJObject(jContainer).OrderBy(s => s).SequenceEqual(GetExpectedDiffStrings().OrderBy(s => s)));
static IEnumerable<string> GetExpectedDiffStrings()
var strings = @"lastName/new:Bab/old:Beb
middleName/new:Cg/old:seeg
contact.emailAddress/new:bab@example.com/old:beb@example.com
contact.addresses[0].state/new:AL/old:AZ
contact.addresses[1].state/new:TN/old:MO";
return strings.Split(new [] { '\r', '\n' });
public static void Main()
Console.WriteLine("Environment version: {0} ({1})", System.Runtime.InteropServices.RuntimeInformation.FrameworkDescription , GetNetCoreVersion());
Console.WriteLine("Json.NET 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];