title: How to deserialize Newtonsoft Json.NET references to separate, individual instances
body: <p>I have a piece of JSON that looks like this:</p>
  
  <pre><code>[
    {
      "$id": "1",
      "Name": "James",
      "BirthDate": "1983-03-08T00:00Z",
      "LastModified": "2012-03-21T05:40Z"
    },
    {
      "$ref": "1"
    }
  ]
  </code></pre>
  
  <p>As you can tell by the $ref, this JSON array contains the same Person (James), twice. The second time is a reference to the first.</p>
  
  <p>I am wondering if there is a way to <strong>deserialize</strong> this JSON into an object that contains two <strong>copies</strong> of the James person.</p>
  
  <p>Currently, I'm using this:</p>
  
  <pre><code>var jsonSerializerSettings = new JsonSerializerSettings()
  {
       PreserveReferencesHandling = PreserveReferencesHandling.None,
       ReferenceLoopHandling = ReferenceLoopHandling.Ignore
  };
  
  var deserializedPersons = JsonConvert.DeserializeObject&lt;List&lt;Person&gt;&gt;(json, jsonSerializerSettings);
  </code></pre>
  
  <p>But this just gives me an array with the same instance of the Person, twice:</p>
  
  <pre><code>object.ReferenceEquals(deserializedPersons[0], deserializedPersons[1]) // Evaluates to true
  </code></pre>
  
  <p>I've found a workaround I am unhappy with which is simply deserializing the JSON string, then serializing it using the jsonSerializerSettings above, which will duplicate the person in the JSON, then deserializing it <em>again</em>. This is causing major slowdowns for the large objects we are using.</p>
  
  <p><strong>Note</strong>: I know I could change the API that I retrieve this JSON from to duplicate the data, but preserving the references saves <em>substantial</em> space when sending the response JSON over the wire.</p>