title: aspnet core return json function returning invalid json
body: <p>I have sales and sales item entity where i'm trying to return some json from controller to front end using return <code>json ()</code> function in asp.net core 2.0 </p>
  
  <p>here is my controller code :</p>
  
  <pre><code>[HttpGet]
  public JsonResult GetSales(int saleId)
  {
    SalesModel sales = saleRepository.All().FirstOrDefault(x =&gt; x.Id == saleId);
    sales.Items = saleItemRepository.All().Where(x =&gt; x.SalesId == 
    saleId).ToList();
    return Json(sales);
  } 
  </code></pre>
  
  <p>on the front, using jQuery ajax get call : </p>
  
  <pre><code> function getSale(id) {
       return $.ajax({
                type: 'GET',
                url: "/Sales/GetSales",
                data: "saleId=" + id
           });
   }
  
   $.when(getSale(saleId)).then(function (res) {
        console.log(res);  
        }).fail(function (err) { 
           console.log(err);  
        });
  </code></pre>
  
  <p><strong>on the console i'm getting json, which is invalid : array ending }]} are missing</strong> </p>
  
  <pre><code>{"salesDate":"2018-06-14T00:00:00","saleCode":"1527863276313","notes":"Ok","total":12.31,"status":"Due","discount":0.31,"grandTotal":12.0,"paymentMethod":"Cash","customerId":3,"customerModel":null,"items":[{"name":"hello","price":2.33,"quantity":4,"amount":9.32,"salesId":7
  </code></pre>
  
  <p><a href="https://i.stack.imgur.com/fq9cu.png" rel="nofollow noreferrer">console error image here</a></p>
  
  <p><strong>but while I hardcoded the salesItem, it's returning valid json and it seems ok</strong></p>
  
  <pre><code>public JsonResult GetSales(int saleId)
          {
              SalesModel sales = saleRepository.All().FirstOrDefault(x =&gt; x.Id == saleId);
              SalesItemsModel a = new SalesItemsModel { Name = "abc", Amount = 2.5, Id = 1, IsDelete = false, Price = 2.5, Quantity = 1, SalesId = 5};
              sales.Items.Add(a);
              return Json(sales);
          }
  </code></pre>
  
  <p>what am i missing to get a valid json while fetching from database ? this same code is running perfectly on aspnetmvc 5</p>