title: Return JSON response in array format in ASP.NET MVC 5 C#
body: <p>I want to return JSON format from my database using asp.net mvc5 c#. I tried a lot of ways but was unable to generate data as per my requirement. I need the JSON array in this format.</p>
  <pre><code>{
   &quot;draw&quot;:0,
   &quot;recordsTotal&quot;:2,
   &quot;recordsFiltered&quot;:2, 
   &quot;data&quot;:[
            [
              &quot;126&quot;,
              &quot;Test Name 1&quot;,
              &quot;07.01.2022 11:55 AM&quot;,
              &quot;Male&quot;
            ],
            [
              &quot;127&quot;,
              &quot;Test Name 2&quot;,
              &quot;01.02.2022 11:55 AM&quot;,
              &quot;Male&quot;
            ]
         ]
  }
  </code></pre>
  <p>Instead of this I am getting output in given format</p>
  <pre><code>{
   &quot;draw&quot;:0,
   &quot;recordsTotal&quot;:2,
   &quot;recordsFiltered&quot;:2, 
   &quot;data&quot;:[
            {
              &quot;ID&quot;:126,
              &quot;Name&quot;:&quot;Test Name 1&quot;,
              &quot;Date&quot;:&quot;07.01.2022 11:55 AM&quot;,
              &quot;Gender&quot;:&quot;Male&quot;
            },
            {
              &quot;ID&quot;:127,
              &quot;Name&quot;:&quot;Test Name 2&quot;,
              &quot;Date&quot;:&quot;01.02.2022 11:55 AM&quot;,
              &quot;Gender&quot;:&quot;Male&quot;
            }
         ]
  }
  </code></pre>
  <p>My ASP.NET MVC5 C# code is below</p>
  <pre><code>public ContentResult GetDoctor()
          {
              var doctors = db.Doctors.Where(e =&gt; e.ID &gt; 0);
              var doct = doctors.Select(c =&gt; new
              {
                  ID = c.ID + &quot;,&quot; +
                  &quot;,&quot; + c.Name +
                  &quot;,&quot; + c.Date +
                  &quot;,&quot; + c.Gender
              }).ToList();
              string students = string.Join(&quot;],[&quot;, doct.Select(e =&gt; e.ID.ToString()));
              students = JsonConvert.SerializeObject(students);
              JsonSerializerSettings hg = new JsonSerializerSettings();
              hg.Formatting = Formatting.Indented;
              hg.TypeNameHandling = TypeNameHandling.None;
              string json = JsonConvert.SerializeObject(doctors.ToList(),hg);
              return Content(json.ToString(), &quot;application/json&quot;);
          }
  </code></pre>