title: How do I return a list as a JSON object with a nested array instead of just an array?
body: <p>Using ASP.NET Core web API framework, my controller returns a list, which currently formats its output in JSON as a plain array. How do I wrap an object around this so it outputs as an object with an array nested inside of it instead?</p>
  <p>I know that I can do this by creating a new class to hold this list as a property, but I wanted to know if there is a cleaner way that I can do this code block (especially since the class would only be used for this method).</p>
  <p>My controller code is as follows:</p>
  <pre><code>public async Task&lt;IActionResult&gt; GetIntranets(string utilityServer,
       string configuration) {
  
       List&lt;Intranet&gt; intranets = 
            await _intranetService.GetIntranets(utilityServer, configuration);
              
       return new OkObjectResult(intranets);
  }
  </code></pre>
  <p>Current output:</p>
  <pre><code>[
    {
      &quot;name&quot;: &quot;Intranet 1&quot;,
      &quot;taskmanPath&quot;: &quot;\\\\hostname\\syteline&quot;,
      &quot;reportPreviewUrl&quot;: &quot;https://cname.domain.com/slreports&quot;,
      &quot;reportServerUrl&quot;: &quot;http://hostname/ReportServer_XYZ_TEST&quot;,
      &quot;masterSite&quot;: &quot;DALS&quot;
    },
    {
      &quot;name&quot;: &quot;Intranet 2&quot;,
      &quot;taskmanPath&quot;: &quot;\\\\hostname\\syteline&quot;,
      &quot;reportPreviewUrl&quot;: &quot;https://cname.domain.com/slreports&quot;,
      &quot;reportServerUrl&quot;: &quot;http://fqdn/ReportServer_XYZ_PILOT&quot;,
      &quot;masterSite&quot;: &quot;DALS&quot;
    },
  ]
  </code></pre>
  <p>Desired output:</p>
  <pre><code>{
    &quot;Intranets&quot;: [
      {
        &quot;name&quot;: &quot;Intranet 1&quot;,
        &quot;taskmanPath&quot;: &quot;\\\\hostname\\syteline&quot;,
        &quot;reportPreviewUrl&quot;: &quot;https://cname.domain.com/slreports&quot;,
        &quot;reportServerUrl&quot;: &quot;http://hostname/ReportServer_XYZ_TEST&quot;,
        &quot;masterSite&quot;: &quot;DALS&quot;
      },
      {
        &quot;name&quot;: &quot;Intranet 2&quot;,
        &quot;taskmanPath&quot;: &quot;\\\\hostname\\syteline&quot;,
        &quot;reportPreviewUrl&quot;: &quot;https://cname.domain.com/slreports&quot;,
        &quot;reportServerUrl&quot;: &quot;http://fqdn/ReportServer_XYZ_PILOT&quot;,
        &quot;masterSite&quot;: &quot;DALS&quot;
      }
    ]
  }
  </code></pre>