title: reading nested JSON using JavaScript
body: <p>I'm trying to read the nested content of a JSON file using JavaScript.  </p>
  
  <p>Here is my JavaScript:</p>
  
  <pre><code>&lt;script&gt;
  var obj, xmlhttp, myObj, x, txt = "";
  var request = new XMLHttpRequest();
  request.open('GET', 'https://private-c01be-moneyadviceservice.apiary-mock.com/locale/categories.json');
  request.setRequestHeader("Content-type", "application/json");
  request.onreadystatechange = function () {
  if (this.readyState === 4) {
  console.log('Status:', this.status);
  console.log('Headers:', this.getAllResponseHeaders());
  console.log('Body:', this.responseText);
  
    myObj = JSON.parse(this.responseText);
  
     for (x in myObj) {
          txt += "&lt;h2&gt;" + myObj[x].title + "&lt;/h2&gt;&lt;p&gt;" + myObj[x].description + "&lt;/p&gt;&lt;br/&gt;";
          txt += "&lt;h3&gt;" + myObj[x].contents.title + "&lt;/h3&gt;&lt;p&gt;" + myObj[x].contents.description + "&lt;/p&gt;&lt;br/&gt;";
      }
  
      document.getElementById("MAS").innerHTML = txt; 
    }
  };
  
  request.send();
  &lt;/script&gt;
  </code></pre>
  
  <p>And here is the JSON file:</p>
  
  <pre><code> {
      "id": "life-events",
      "type": "category",
      "title": "Life events",
      "description": "When big things happen - having a baby, losing your job, getting divorced or retiring\n - it helps to be in control of your money\n",
      "contents": [
          {
              "id": "setting-up-home",
              "type": "category",
              "title": "Setting up home",
              "description": "Deciding whether to rent or buy, working out what you can afford and managing\n money when sharing with others\n",
              "contents": [
              ]
          },
          {
              "id": "young-people-and-money",
              "type": "category",
              "title": "Leaving school or college",
              "description": "",
              "contents": [
              ]
          },
          {
              "id": "having-a-baby",
              "type": "category",
              "title": "Having a baby",
              "description": "",
              "contents": [
              ]
          }
      ]
  },
  </code></pre>
  
  <p>The nested JSON is showing as 'Undefined'.  How do I access the nested data?</p>
  
  <p>I've read countless posts about this topic but none have really helped in this instance</p>