title: How Do I convert my array of objects into JSON object in C# (.net core)
body: <p>I'm working in .Net Core 2.2 with the MVC pattern. I have a Web-API controller, where I created some Endpoints with classic CRUD-methods.</p>
  
  <p>Now I have everything compiling and when I debug my soluting I get an array containing a couple of JSON-formatted objects - but the system sees the output it as an array, not as JSON.</p>
  
  <p>Now I want this array to become a JSON.</p>
  
  <p>I've looked at this: <a href="https://www.newtonsoft.com/json/help/html/T_Newtonsoft_Json_Linq_JObject.htm" rel="nofollow noreferrer">https://www.newtonsoft.com/json/help/html/T_Newtonsoft_Json_Linq_JObject.htm</a></p>
  
  <p>My orginal method looked like this (in controller): </p>
  
  <pre><code>[HttpGet("/ListAllItems")]
  public async Task&lt;IEnumerable&lt;DtoModel&gt;&gt; ListAllItemsFromDb()
  {
      return  await _dbProvider.ListAllItemsAsync();
  }
  </code></pre>
  
  <p>and gave an output of:</p>
  
  <pre><code>[{"id": "GUID-STRING", "itemName": "foo"}, {"id": "GUID-STRING2", "itemName": "bar"}]
  
  //My frontend did not recognize this as a JSON, since it is an array, and threw an exception
  </code></pre>
  
  <p>So I tried this in my controller instead</p>
  
  <pre><code>  [HttpGet("/ListAllItems")]
          public async Task&lt;JObject&gt; ListAllItemsFromDb()
          {
              var result = await _dbProvider.ListAllItemsAsync();
              string output = result.ToString(); 
              string json = JsonConvert.SerializeObject(output);
              JObject obj = JObject.Parse(json);
              return obj; 
          }
  </code></pre>
  
  <p>When I run this code, my error message states: "JsonReaderException: Error reading JObject from JsonReader. Current JsonReader item is not an object: String. Path '', line 1, position 60."</p>
  
  <p>How do I make the array of objects into a JSON object?</p>