using System.Collections;
using System.Collections.Generic;
using System.Runtime.Serialization.Formatters;
using System.ComponentModel.DataAnnotations;
using System.Globalization;
using System.Data.DataSetExtensions;
public static void Test()
var dataTable = MakeTable();
var propertyKey = "Block";
var valuesKey = "HouseNo";
var dictionary = dataTable.AsEnumerable()
.GroupBy(r => r.Field<string>(propertyKey), r => r.Field<string>(valuesKey))
.ToDictionary(g => propertyKey + " " + g.Key, g => g.ToArray());
var json = JsonConvert.SerializeObject(dictionary, Formatting.Indented);
Console.WriteLine("\nOutput JSON:");
Console.WriteLine("\nInput DataTable was:");
Console.WriteLine(JsonConvert.SerializeObject(dataTable, Formatting.Indented));
static DataTable MakeTable()
var dt = new DataTable();
dt.Columns.Add(new DataColumn("Block", typeof(string)));
dt.Columns.Add(new DataColumn("HouseNo", typeof(string)));
foreach (var line in data)
row["HouseNo"] = line[1];
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");