title: How to deserialise a JSON object where the object structure is not known
body: <p>Part of my code serializes file paths of a machine into JSON in the below format. I am struggling to take this JSON and put the file paths back together again.  I am using Newtonsoft JSON lib; I find it's excellent for building JSON. As you can see, my JSON has nested objects.</p>
  
  <p>The JSON I have:</p>
  
  <pre><code>{
    ".": {
      "proc": {
        "15": {
          "task": {
            "15": {
              "exe": {},
              "mounts": {
                "list_of_files": [
                  "mounts.xml"
                ]
              },
              "mountinfo": {
                "list_of_files": [
                  "mountinfo.xml"
                ]
              },
              "clear_refs": {
                "list_of_files": [
                  "clear_ref.xml"
                ]
              }
            }
          }
        },
        "14": {
          "loginuid": {
            "list_of_files": [
              "loginuid.xml"
            ]
          },
          "sessionid": {
            "list_of_files": [
              "sessionid.xml"
            ]
          },
          "coredump_filter": {
            "list_of_files": [
              "coredump_filter.xml"
            ]
          },
          "io": {
            "list_of_files": [
              "io.xml"
            ]
          }
        }
      }
    }
  }
  </code></pre>
  
  <p>The array I want to generate from this.</p>
  
  <pre><code>string[] dirArray = {
  "./proc/15/task/15/exe",
  "./proc/15/task/15/mounts/mounts.xml",
  "./proc/15/task/15/mountinfo/mountinfo.xml",
  "./proc/15/task/15/clear_refs/clear_ref.xml",
  "./proc/14/loginuid/loginuid.xml",
  "./proc/14/sessionid/sessionid.xml",
  "./proc/14/coredump_filter/coredump_filter.xml",
  "./proc/14/io/io.xml"
  }
  </code></pre>
  
  <p>My efforts so far-- I deserialised the JSON into a dynamic variable but I'm not sure how to handle two issues:</p>
  
  <ol>
  <li>My JSON format is unknown, I don't know how deep the objects go, how can I handle this?</li>
  <li>How do I work with dynamic variables when they are defined at run-time?</li>
  </ol>
  
  <p><strong>EDIT</strong></p>
  
  <p>Sorry, my original JSON format was wrong, so it doesn't work with the <a href="https://stackoverflow.com/a/26717924/10263">answer</a> provided by user12864.  I'm getting an error: <code>Unable to cast object of type 'Newtonsoft.Json.Linq.JArray' to type 'Newtonsoft.Json.Linq.JObject'.</code></p>
  
  <p>Here is a <a href="https://dotnetfiddle.net/XUrFG4" rel="nofollow noreferrer">fiddle</a> showing where I'm at so far.</p>