title: Parsing a JSON response from URL
body: <p>My requirement is to parse a JSON response from a URL response.
  The JSON feed is comprised of two list namely:</p>
  
  <p>a. "Ownerships" - This list will contain two main attributes </p>
  
  <ol>
  <li>NodeCode </li>
  <li>ParentCode</li>
  </ol>
  
  <p>b. "Nodes" - This list consists of two attributes  </p>
  
  <ol>
  <li>NodeCode (NodeCode is the Primary Identifier of each node)</li>
  <li>NodeType (NodeType can have values like "LEVEL01", "LEVEL02" ,..., "LEVEL06")</li>
  </ol>
  
  <p>The logic is:</p>
  
  <ul>
  <li><p>For each NodeCode value in "Nodes" scan the "Ownerships" list to get the related ParentCode</p></li>
  <li><p>Come back to the "Nodes" list and search for the ParentCode obtained in the earlier step as NodeCode, and get the corresponding "NodeType"</p></li>
  <li><p>Repeat earlier steps till all NodeCodes are parsed, so that at the end you will have something like below(all these columns will be for a single record):</p>
  
  <p><code>LEVEL01NodeCode
  LEVEL02NodeCode
  LEVEL03NodeCode
  LEVEL04NodeCode
  LEVEL05NodeCode
  LEVEL06NodeCode</code></p></li>
  </ul>
  
  <p>Bottom line
  <strong>Starting from the lowest level(assuming LEVEL01), scan Nodes and Ownerhips lists, get the NodeCode corresponding to the level, and keep searching based on ParentCode till all the top levels are covered.</strong></p>
  
  <p>The problem here is:
  <strong>A NodeCode which is at LEVEL01 may have a ParentCode which can reside in ANY ONE of the levels above(it may be at LEVEL03, LEVEL04 or even at LEVEL06)</strong></p>
  
  <p>How to flatten this kind of data structure?</p>
  
  <p>Sample Data structure:</p>
  
  <pre><code>{
     "Ownerships":[
        {
           "ParentCode":"XX01",
           "NodeCode":"TT01"
        },
        {
           "ParentCode":"XX02",
           "NodeCode":"TT02"
        }
     ],
     "Nodes":[
        {
           "NodeCode":"TT02",
           "NodeType ":"LEVEL01"
        },
        {
           "NodeCode":"XX02",
           "NodeType ":"LEVEL03"
        },
        {
           "NodeCode":"XX01",
           "NodeType ":"LEVEL05"
        }
     ]
  }
  </code></pre>