title: Generating JSON from nested Dictionary in C#
body: <p>I have the following Dictionary:</p>
  <pre><code>Dictionary&lt;string, Dictionary&lt;string, List&lt;ChartData&gt;&gt;&gt; data;
  </code></pre>
  <p>ChartData implementation looks like this:</p>
  <pre><code>   public struct ChartData
      {
          public long datetime;
          public double open;
          public double high;
          public double low;
          public double close;
          public ulong tick_volume;
          public int spread;
          public ulong volume;
      }
  </code></pre>
  <p>I want to generate JSON using the data I have in my data container. My data must look something like that:</p>
  <pre><code>{
      &quot;EURUSD&quot;: [
          {
              &quot;PROV&quot;: [
                  {
                      &quot;datetime&quot;:34534554,
                      &quot;open&quot;:2.31,
                      &quot;high&quot;:123,
                      &quot;low&quot;:3213,
                      &quot;close&quot;:213,
                      &quot;tick_volume&quot;:2131,
                      &quot;spread&quot;:2131,
                      &quot;volume&quot;:3123
                  },
                  {
                      &quot;datetime&quot;:34534554,
                      &quot;open&quot;:2.31,
                      &quot;high&quot;:123,
                      &quot;low&quot;:3213,
                      &quot;close&quot;:213,
                      &quot;tick_volume&quot;:2131,
                      &quot;spread&quot;:2131,
                      &quot;volume&quot;:3123
                  }
              ],
              &quot;LMAX&quot;:[
                  {
                      &quot;datetime&quot;:34534554,
                      &quot;open&quot;:2.31,
                      &quot;high&quot;:123,
                      &quot;low&quot;:3213,
                      &quot;close&quot;:213,
                      &quot;tick_volume&quot;:2131,
                      &quot;spread&quot;:2131,
                      &quot;volume&quot;:3123
                  }
              ]
          }
      ],
      &quot;BTCUSD&quot;:[
          {
              &quot;PROV&quot;:[
                  {
                      &quot;datetime&quot;:34534554,
                      &quot;open&quot;:2.31,
                      &quot;high&quot;:123,
                      &quot;low&quot;:3213,
                      &quot;close&quot;:213,
                      &quot;tick_volume&quot;:2131,
                      &quot;spread&quot;:2131,
                      &quot;volume&quot;:3123
                  }
              ]
          }
      ]
  }
  </code></pre>
  <p>The solution I have right now is this:</p>
  <pre><code>   var jsonObjectData= JObject.Parse(System.Text.Json.JsonSerializer.Serialize(data));
      var result = new JObject();
  
      result.Merge(jsonObjectData);
  
      var json = result.ToString(Newtonsoft.Json.Formatting.Indented);
  </code></pre>
  <p>But I don't see any correct data here.</p>
  <p>Do you have any suggestions, that I could use to generate the required JSON from my nested Dictionary container ?</p>
  <p>I would appreciate any help.</p>