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 void Test()
var inputJson = GetJson();
var inputArray = JsonConvert.DeserializeObject<KeyValuePair<string, JToken> [][]>(inputJson);
var outputArray = inputArray.Select(a => new JObject(a.Select(o => (new JProperty(o.Key, o.Value)))));
var outputJson = JsonConvert.SerializeObject(outputArray, Formatting.Indented);
Console.WriteLine(outputJson);
Assert.IsTrue(JToken.DeepEquals(JToken.Parse(outputJson), JToken.Parse(GetRequiredJson())), "Generated and required JSON are NOT equivalent!");
Console.WriteLine("Generated and required JSON are equivalent.");
[{""Key"":""entity_id"",""Value"":""1""},{""Key"":""CustomerName"",""Value"":""Test1""},{""Key"":""AccountNumber"",""Value"":""ACC17-001""},{""Key"":""CustomerType"",""Value"":""Direct Sale""}],
[{""Key"":""entity_id"",""Value"":""2""},{""Key"":""CustomerName"",""Value"":""Test2""},{""Key"":""AccountNumber"",""Value"":""ACC17-002""},{""Key"":""CustomerType"",""Value"":""Direct Sale""}],
[{""Key"":""entity_id"",""Value"":""3""},{""Key"":""CustomerName"",""Value"":""Test3""},{""Key"":""AccountNumber"",""Value"":""ACC17-003""},{""Key"":""CustomerType"",""Value"":""Direct Sale""}],
[{""Key"":""entity_id"",""Value"":""4""},{""Key"":""CustomerName"",""Value"":""Test4""},{""Key"":""AccountNumber"",""Value"":""ACC17-004""},{""Key"":""CustomerType"",""Value"":""Direct Sale""}],
[{""Key"":""entity_id"",""Value"":""5""},{""Key"":""CustomerName"",""Value"":""Test5""},{""Key"":""AccountNumber"",""Value"":""ACC17-005""},{""Key"":""CustomerType"",""Value"":""Invoice""}],
[{""Key"":""entity_id"",""Value"":""6""},{""Key"":""CustomerName"",""Value"":""Test6""},{""Key"":""AccountNumber"",""Value"":""ACC17-006""},{""Key"":""CustomerType"",""Value"":""Invoice""}]
static string GetRequiredJson()
{""entity_id"":""1"",""CustomerName"":""Test1"",""AccountNumber"":""ACC17-001"",""CustomerType"":""Direct Sale""},
{""entity_id"":""2"",""CustomerName"":""Test2"",""AccountNumber"":""ACC17-002"",""CustomerType"":""Direct Sale""},
{""entity_id"":""3"",""CustomerName"":""Test3"",""AccountNumber"":""ACC17-003"",""CustomerType"":""Direct Sale""},
{""entity_id"":""4"",""CustomerName"":""Test4"",""AccountNumber"":""ACC17-004"",""CustomerType"":""Direct Sale""},
{""entity_id"":""5"",""CustomerName"":""Test5"",""AccountNumber"":""ACC17-005"",""CustomerType"":""Invoice""},
{""entity_id"":""6"",""CustomerName"":""Test6"",""AccountNumber"":""ACC17-006"",""CustomerType"":""Invoice""}
public static void Main()
Console.WriteLine("Environment version: " + Environment.Version);
Console.WriteLine("Json.NET version: " + typeof(JsonSerializer).Assembly.FullName);
Console.WriteLine("Failed with unhandled exception: ");
public class AssertionFailedException : System.Exception
public AssertionFailedException() : base() { }
public AssertionFailedException(string s) : base(s) { }
public static class Assert
public static void IsTrue(bool value)
public static void IsTrue(bool value, string message)
throw new AssertionFailedException(message ?? "failed");