You're on the right track. To get the structure you outlined in your question, you need to use a dictionary of dictionaries representing mappings of store number to quantity per SKU. The class would look like this:
class RootObject
{
[JsonProperty("skus")]
public Dictionary<string, Dictionary<string, int>> Skus { get; set; }
}
You will need a small amount of code to group your data table rows into the nested dictionaries, as shown below. Note: this code assumes that each store number will be encountered only once per SKU. If this is not the case, you will need to adjust it accordingly.
DataTable table = new DataTable();
table.Columns.Add("sku", typeof(int));
table.Columns.Add("store", typeof(int));
table.Columns.Add("qty", typeof(int));
table.Rows.Add(20000, 100, 3);
table.Rows.Add(20000, 132, 1);
table.Rows.Add(20000, 320, 0);
table.Rows.Add(30000, 243, 2);
table.Rows.Add(30000, 210, 1);
table.Rows.Add(10000, 410, 5);
var skus = new Dictionary<string, Dictionary<string, int>>();
foreach (DataRow row in table.Rows)
{
string sku = row["sku"].ToString();
Dictionary<string, int> stores;
if (!skus.TryGetValue(sku, out stores))
{
stores = new Dictionary<string, int>();
skus.Add(sku, stores);
}
stores.Add(row["store"].ToString(), (int)row["qty"]);
}
RootObject root = new RootObject { Skus = skus };
Once you have the data gathered into your RootObject, it is trivial to serialize it to JSON using Json.Net:
string json = JsonConvert.SerializeObject(root, Formatting.Indented);
Deserializing the JSON back to your RootObject is just as easy:
RootObject root = JsonConvert.DeserializeObject<RootObject>(json);
Here is a full round-trip demo: https://dotnetfiddle.net/qR3wbE