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 decimal cost { get; set; }
public int count { get; set; }
public static class ProductConstants
static ReadOnlyCollection<string> wellKnownStores = new ReadOnlyCollection<string>(new [] { "StoreOne", "StoreTwo" });
public static IReadOnlyCollection<string> WellKnownStores => wellKnownStores;
static ReadOnlyCollection<string> wellKnownProducts = new ReadOnlyCollection<string>(new [] { "va", "ok", "wa", "vi", "tg" });
public static IReadOnlyCollection<string> WellKnownProducts => wellKnownProducts;
public static void Test()
var data = JsonConvert.DeserializeObject<Dictionary<string, Dictionary<string, Product>>>(json);
foreach (var store in ProductConstants.WellKnownStores)
Console.WriteLine("Products for {0}: {1}.", store,
string.Join(",", data.GetValueOrDefault(store)?.Keys ?? (IEnumerable<string>)new [] {"None"}));
var json2 = JsonConvert.SerializeObject(data, Formatting.Indented);
Console.WriteLine("Re-serialized JSON:");
Console.WriteLine(json2);
""StoreOne"": { // <--- Store Name
""vk"": { // <--- Store Product
""cost"": 19, // <--- information about product
""count"": 1903 // <--- information about product
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];