How to create column and row wise json structure?
<p>I am trying to create json structure like below:</p>
<pre><code>{
  &quot;cols&quot;: [
    {
      label: &quot;Types&quot;,
      type: &quot;string&quot;
    },
    {
      label: &quot;values&quot;,
      type: &quot;number&quot;
    }
  ],
  &quot;rows&quot;: [
    {
      c: [
        {
          v: &quot;Mushrooms&quot;
        },
        {
          v: 3
        },
        
      ]
    },
    {
      c: [
        {
          v: &quot;Olives&quot;
        },
        {
          v: 31
        }
      ]
    },
    {
      c: [
        {
          v: &quot;Zucchini&quot;
        },
        {
          v: 1
        },
        
      ]
    },
    {
      c: [
        {
          v: &quot;Pepperoni&quot;
        },
        {
          v: 2
        },
        
      ]
    }
  ]
}
</code></pre>
<p>This  above values I am getting from here:</p>
<pre><code>public class Type
{
    public int Mushrooms { get; set; }
    public int Olives { get; set; }
    public int Zucchini { get; set; }
    public int Pepperoni { get; set; }
  public int Statistics { get; set; } //Ignore properties in final output
    public int Count { get; set; } //Ignore properties in final output
    public int Average { get; set; } //Ignore properties in final output
}

var types = MyRepository&lt;Type&gt;.FirstorDefault();
</code></pre>
<p>The above query outputs:</p>
<blockquote>
<p>Mushrooms:3</p>
<p>Olives:31 etc..</p>
</blockquote>
<p>This is how I have designed a class:</p>
<pre><code>public class Cols
{
    public List&lt;Names&gt; Names { get; set; }

}

public class Names
{
    public string label { get; set; }
    public string type { get; set; }
}
</code></pre>
<p>But I am getting an output like this:</p>
<pre><code>&quot;data&quot;: [
    {
      &quot;Names&quot;: [
        {
          &quot;label&quot;: &quot;Types&quot;,
          &quot;type&quot;: &quot;string&quot;
        },
        {
          &quot;label&quot;: &quot;values&quot;,
          &quot;type&quot;: &quot;number&quot;
        }
      ]
    }
  ]
</code></pre>
<p><strong>Update:</strong> Class design</p>
<pre><code> public class Rootobject
    {
        public List&lt;Names&gt; cols { get; set; }
        public List&lt;Row&gt; rows { get; set; }
    }

    public class Names
    {
        public string label { get; set; }
        public string type { get; set; }
    }

    public class Row
    {
        public List&lt;C&gt; c { get; set; }
    }

    public class C
    {
        public object v { get; set; } 
    }
</code></pre>
<p>Still above class design gives me below json structure:</p>
<pre><code>{
  &quot;Data&quot;: {
    &quot;cols&quot;: [
      {
        &quot;label&quot;: &quot;Types&quot;,
        &quot;type&quot;: &quot;string&quot;
      },
      {
        &quot;label&quot;: &quot;values&quot;,
        &quot;type&quot;: &quot;number&quot;
      }
    ],
    &quot;rows&quot;: [
      {
        &quot;c&quot;: [
          {
            &quot;v&quot;: &quot;Mushrooms&quot;
          },
          {
            &quot;v&quot;: &quot;3&quot;
          },
          {
            &quot;v&quot;: &quot;Olives&quot;
          },
          {
            &quot;v&quot;: &quot;31&quot;
          },
          {
            &quot;v&quot;: &quot;Zucchini&quot;
          },
          {
            &quot;v&quot;: &quot;1&quot;
          },
          {
            &quot;v&quot;: &quot;Pepperoni&quot;
          },
          {
            &quot;v&quot;: &quot;2&quot;
          }
        ]
      }
    ]
  }
}
</code></pre>
<p>For Returning json data I am using this <a href="https://msdn.microsoft.com/en-us/library/system.web.mvc.jsonresult(v=vs.118).aspx" rel="nofollow noreferrer">json</a> class of asp.net mvc.</p>
<pre><code>return Json(new {Data = rootObject }, JsonRequestBehavior.AllowGet);
</code></pre>