title: How do I disable object reference creation in the Newtonsoft JSON serializer?
body: <p>I switched my ASP.NET MVC application to use the Newtonsoft JsonSerializer to do our JSON serialization, as such:</p>
  
  <pre><code>var writer = new JsonTextWriter(HttpContext.Response.Output) { Formatting = Formatting };
  var serializer = JsonSerializer.Create();
  serializer.Serialize(writer, myData);
  </code></pre>
  
  <p>This generates some JSON that has $id and $ref properties and then removes duplicate objects from the JSON.  I know it's a feature that is great, but the clients that read this JSON cannot support interpreting these references and expect full objects to be there.  I've tried setting the <code>PreserveReferencesHandling</code> property on the <code>JsonSerializerSettings</code> to every possible value and it doesn't seem to make any difference.</p>
  
  <p>How can I disable the creation of the $id and $ref properties and get the Newtonsoft serializer to write out the whole object graph?</p>
  
  <p><strong>EDIT</strong>: here is a sample C# class, the JSON I expect, and the JSON created by the Newtonsoft serializer:</p>
  
  <pre><code>public class Product
  {
      public Image MainImage { get; set; }
  
      public List&lt;Image&gt; AllImages { get; set; }
  }
  
  public class Image
  {
      public int Id { get; set; }
      public string Url { get; set; }
  }
  </code></pre>
  
  <p>JSON I expect:</p>
  
  <pre><code>{
      MainImage: { Id: 1, Url: 'http://contoso.com/product.png' },
      AllImages: [{ Id: 1, Url: 'http://contoso.com/product.png' },{ Id: 2, Url: 'http://contoso.com/product2.png' }]
  }
  </code></pre>
  
  <p>JSON created by the Newtonsoft serializer (note the added $id parameter in MainImage and the referenced object being completely replaced by a $ref parameter):</p>
  
  <pre><code>{
      MainImage: { $id: 1, Id: 1, Url: 'http://contoso.com/product.png' },
      AllImages: [{ $ref: 1 },{ Id: 2, Url: 'http://contoso.com/product2.png' }]
  }
  </code></pre>
  
  <p>I understand that the Newtonsoft version is better (it's DRYer) but the client that reads this JSON output does not understand what $ref means.</p>