using System.Collections;
using System.Collections.Generic;
using System.Runtime.Serialization.Formatters;
using System.ComponentModel.DataAnnotations;
using System.Globalization;
using System.Collections.ObjectModel;
using Newtonsoft.Json.Linq;
using Newtonsoft.Json.Converters;
using Newtonsoft.Json.Serialization;
public static void Test()
TestArraySlice(GetJson());
TestSelectWithNestedArraySlice(GetJson());
static void TestArraySlice(string json)
Console.WriteLine("Array slice results:");
var data = JToken.Parse(GetJson());
var query = data.SelectTokens("Values[*]['Name','Address']")
.Select(v => (JProperty)v.Parent)
.Select(g => new JObject(g));
Console.WriteLine(JsonConvert.SerializeObject(query, Formatting.Indented));
static void TestSelect(string json)
Console.WriteLine("Select results:");
var data = JToken.Parse(GetJson());
var query = data.SelectTokens("Values[*]")
.Select(o => new JObject(o.Property("Name"), o.Property("Address")));
Console.WriteLine(JsonConvert.SerializeObject(query, Formatting.Indented));
static void TestSelectWithNestedArraySlice(string json)
Console.WriteLine("Select with nested array slice results:");
var data = JToken.Parse(GetJson());
var query = data.SelectTokens("Values[*]")
.Select(o => new JObject(o.SelectTokens("['Name','Address']").Select(v => (JProperty)v.Parent)));
Console.WriteLine(JsonConvert.SerializeObject(query, Formatting.Indented));
""Address"": ""1234 Easy St.""
""Address"": ""1600 Pennsylvania Ave.""
""Address"": ""653 28th St NW""
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];