title: How can I select an object type to deserialize using Json.Net based on property values in the data
body: <p>I need to deserialize json like this (it's as defined in DICOM - an international standard, so I can't change the format!)  </p>
  
  <pre><code>{
  ....
  "00080060": {
    "Value": [
      "US"
    ],
    "vr": "CS"
  },
  "00080070": {
    "Value": [
      "ACME Products"
    ],
    "vr": "LO"
  },
  "00080090": {
    "Value": [
      {
        "AlphabeticName": "Better^Make^U.^MD"
      }
    ],
    "vr": "PN"
  },
  "00081110": {
    "Value": [
      {
        "00080008": {
          "Value": [
            "XX_0",
            "OIU",
            null,
            "PPP"
          ],
          "vr": "CS"
        }
      },
      {},
      {
        "00080008": {
          "Value": [
            "XX_2",
            "OIU",
            null,
            "PPP"
          ],
          "vr": "CS"
        }
      }
    ],
    "vr": "SQ"
  },
  </code></pre>
  
  <p>Each property (in a long list!) has a name (0008XXXX in example above), and has sub-properties "vr" and Value.  In most cases, Value is simply an array of objects (string or number) and that's fine, but for 2 special cases (PN and SQ as above) it needs special handling, and in the case of SQ it is actually an array of the top level object again (which can be nested recursively ad infinitum...)</p>
  
  <p>So - what I need is a simple method, during deserialization to inspect the "vr" value and to give json.net the type it should use for the associated "Value" - is there a simple means to do that?  Of course, the fact that vr could come before or after Value (depending on remote implementation) might complicate things further...</p>
  
  <p>I've looked at json.net's ContractResolver and JsonConverter mechanisms, but ContractResolver seems not to give me access to the data being read in order to allow to make the choice, and JsonConverter derived classes would seem to leave me having to re-implement most of what json.net is dong (otherwise so well!) for me already :-(</p>
  
  <p>Am I missing some obvious and simple solution here?</p>