title: Nested json object deserializing using Delphi 2012
body: <p>I'm working on a wrapper for dropbox in delphi 2012. The problem I'm running into is deserializing the json responses. When I make the request for a list of folders and files in my account I get a response that looks something like this:</p>
  
  <pre><code>{
      "hash": "some_hash",
      "thumb_exists": false, 
      "bytes": 0,
      "path": "/", 
      "is_dir": true, 
      "size": "0 bytes", 
      "root": "dropbox", 
      "contents": 
      [
          {
              "revision": 11, 
              "rev": "b074cbcbb", 
              "thumb_exists": false, 
              "bytes": 0, 
              "modified": "Mon, 23 Apr 2012 19:19:27 +0000", 
              "path": "/Apps", 
              "is_dir": true, 
              "icon": "folder", 
              "root": "dropbox", 
              "size": "0 bytes"
          }, 
          {    
              "revision": 142, 
              "rev": "8e074cbcbb", 
              "thumb_exists": false, 
              "bytes": 0, 
              "modified": "Wed, 09 May 2012 22:55:44 +0000", 
              "path": "/code", 
              "is_dir": true, 
              "icon": "folder", 
              "root": "dropbox", 
              "size": "0 bytes"
          },
          {
              "revision": 7,
              "rev": "7074cbcbb", 
              "thumb_exists": false, 
              "bytes": 246000, 
              "modified": "Mon, 23 Apr 2012 18:40:51 +0000", 
              "client_mtime": "Mon, 23 Apr 2012 18:40:52 +0000", 
              "path": "/Getting Started.pdf", 
              "is_dir": false, 
              "icon": "page_white_acrobat", 
              "root": "dropbox", 
              "mime_type": "application/pdf", 
              "size": "240.2 KB"
          }
      ],
      "icon": "folder"
  }
  </code></pre>
  
  <p>I would like to be able to parse that using a TJSONUnMarshal object, but it turns out that TJSONUnMarshal expects the json to look like this instead:</p>
  
  <pre><code>{
  "type":"DropboxApiU.TFile",
  "id":1,
  "fields":
  {
      "hash": "some_hash",
      "thumb_exists": false, 
      "bytes": 0,
      "path": "/", 
      "is_dir": true, 
      "size": "0 bytes", 
      "root": "dropbox", 
      "contents": 
      [
          {
              "type":"DropboxApiU.TFile",
              "id":1,
              "fields":
              {
                  "revision": 11, 
                  "rev": "b074cbcbb", 
                  "thumb_exists": false, 
                  "bytes": 0, 
                  "modified": "Mon, 23 Apr 2012 19:19:27 +0000", 
                  "path": "/Apps", 
                  "is_dir": true, 
                  "icon": "folder", 
                  "root": "dropbox", 
                  "size": "0 bytes"
              }
          },
  </code></pre>
  
  <p>I've looked at <a href="http://www.danieleteti.it/2009/09/01/custom-marshallingunmarshalling-in-delphi-2010/" rel="nofollow noreferrer">this</a> page and thought it might be what I'm looking for, but it never really goes into how to use a TTypeObjectReverter (which I think is what I need to use) and I can't seem to find an example online.</p>
  
  <p>What would be the best way to make this happen? I'm hoping I can just write a TTypeObjectReverter, or something similar, but I would need to see a sample to be able to wrap my head around that.</p>
  
  <p><strong>edit</strong>
  Here's a screenshot of the differences between the two. The red is not sent in the response from the dropbox server, but is expected by the unmarshaler.</p>
  
  <p><img src="https://i.stack.imgur.com/4oj2P.png" alt="Differences"></p>