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 string name { get; set; }
public string requested_date { get; set; }
public static void Test()
var stringCachedAddresses = GetJson();
TestDeserialize(stringCachedAddresses);
TestDistinct(stringCachedAddresses);
public static void TestDeserialize(string stringCachedAddresses)
var parsedObject = JArray.Parse(stringCachedAddresses);
var requested_date = "2019-06-28";
var pathTemplate = "[*].properties.*[?(@.requested_date == '{0}')]";
var path = string.Format(pathTemplate, requested_date);
var query = parsedObject.SelectTokens(path)
.Select(t => t.ToObject<Sales>());
var list = query.ToList();
Console.WriteLine("\nResult of selecting all {0} objects using the path \"{1}\":", typeof(Sales), path);
Console.WriteLine(JsonConvert.SerializeObject(list, Formatting.Indented));
Assert.IsTrue(list.All(s => s.requested_date == requested_date));
public static void TestDistinct(string stringCachedAddresses)
var parsedObject = JArray.Parse(stringCachedAddresses);
var query = parsedObject.SelectTokens("[*].properties.*[*].requested_date")
.Select(t => t.ToString())
var list = query.ToList();
Console.WriteLine("\nAll distinct requested_date values:");
Console.WriteLine(JsonConvert.SerializeObject(list));
Assert.IsTrue(list.Count == 2 && list.Contains("2019-06-28") && list.Contains( "2019-06-29"));
""requested_date"": ""2019-06-28""
""requested_date"": ""2019-06-28""
""requested_date"": ""2019-06-29""
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: ");