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;
public static partial class JsonExtensions
public static IEnumerable<string> GetDiffPaths(this JContainer root)
throw new ArgumentNullException(nameof(root));
var query = from array in root.DescendantsAndSelf().OfType<JArray>()
where array.Count == 2 && array[0] is JValue && array[1] is JValue
select $"{array.Path}/new:{array[0]}/old:{array[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 JContainer;
throw new JsonException("Input was not a container");
foreach (var item in jContainer.GetDiffPaths())
Assert.IsTrue(jContainer.GetDiffPaths().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];