title: how to access json data contained in a GET response
body: <p>Continuing yesterday's saga, now I can retrieve json objects in a response but I can't extract the data from them.</p>
  
  <p>The following node.js snippet is from the file "accounts.js" which is in an ETrade api library that exists in the path /lib.  It returns json containing data about the accounts of the authenticated user. The authentication part is working great. </p>
  
  <p><div class="snippet" data-lang="js" data-hide="false" data-console="true" data-babel="false">
  <div class="snippet-code">
  <pre class="snippet-code-js lang-js prettyprint-override"><code>exports.listAccounts = function(successCallback,errorCallback)
  {
      var actionDescriptor = {
              method : "GET",
              module : "accounts",
              action : "accountlist",
              useJSON: true,
      };
      
      this._run(actionDescriptor,{},successCallback,errorCallback);
  };</code></pre>
  </div>
  </div>
  </p>
  
  <p>The ETrade website says this call will produce the following sample response:</p>
  
  <p><div class="snippet" data-lang="js" data-hide="false" data-console="true" data-babel="false">
  <div class="snippet-code">
  <pre class="snippet-code-js lang-js prettyprint-override"><code>{
     "AccountListResponse": {
       "Account": [
         {
           "accountDesc": "MyAccount-1",
           "accountId": "83405188",
           "marginLevel": "MARGIN",
           "netAccountValue": "9999871.82",
           "registrationType": "INDIVIDUAL"
         },
         {
           "accountDesc": "MyAccount-3",
           "accountId": "83405553",
           "marginLevel": "CASH",
           "netAccountValue": "100105468.99",
           "registrationType": "INDIVIDUAL"
         },
         {
           "accountDesc": "SIMPLE IRA",
           "accountId": "83405188",
           "marginLevel": "CASH",
           "netAccountValue": "99794.13",
           "registrationType": "IRA"
         }
       ]
     }
   }</code></pre>
  </div>
  </div>
  </p>
  
  <p>In my app.js file, I have the following:</p>
  
  <p><div class="snippet" data-lang="js" data-hide="false" data-console="true" data-babel="false">
  <div class="snippet-code">
  <pre class="snippet-code-js lang-js prettyprint-override"><code>var etrade = require('./lib/etrade');
  var et = new etrade(configuration);
  
  
          et.listAccounts( 
              function(res){
                  var listAccountsRes = res;            
                  console.log('account list success!');
                  console.log(listAccountsRes)
          },
              function(error) {
                  console.log("Error encountered while attempting " +
                              "to retrieve account list: " +
                               error);
          });</code></pre>
  </div>
  </div>
  </p>
  
  <p>When I run this code, the console log shows the following message:</p>
  
  <p><div class="snippet" data-lang="js" data-hide="false" data-console="true" data-babel="false">
  <div class="snippet-code">
  <pre class="snippet-code-js lang-js prettyprint-override"><code>{ 'json.accountListResponse':
    { response:
       [ [Object],
       [ [Object],
       [ [Object],
       [ [Object],
       [ [Object],
       [ [Object],
       [ [Object],
       [ [Object] ] } }      </code></pre>
  </div>
  </div>
  </p>
  
  <p>Suppose in app.js I want to put the accounts data in a variable called myAccounts.  </p>
  
  <p>One of our members, Jack, solved yesterday's problem and when I commented that I still couldn't access the data in the response, he suggested this: "That property has a dot in it so you'll have to use [ ... ] rather than dot notation to access it. See what's inside the objects with a['json.accountListResponse'].response."  So far I have not been able to get that to work, even when I use <code>['json.accountListResponse'].res</code> like this:</p>
  
  <pre><code>var listAccountsRes = [json.accountListResponse].res;            
  </code></pre>
  
  <p>This returns undefined when printed to the console.</p>
  
  <p>Thanks to Adam for his suggestion which led to this which works:</p>
  
  <p><div class="snippet" data-lang="js" data-hide="false" data-console="true" data-babel="false">
  <div class="snippet-code">
  <pre class="snippet-code-js lang-js prettyprint-override"><code>var listAccountsRes = res['json.accountListResponse'];
                  var listAccounts = listAccountsRes['response'];
                  console.log('account list success!');
                  console.log(listAccounts)</code></pre>
  </div>
  </div>
  </p>
  
  <p>Now the console log reports almost exactly what ETrade says I should get. (They appear to have changed the name "Account" to "response").  I presume my variable listAccounts now contains the json with eight sample accounts in it that I can see in my console log.  But I still don't know how to access individual elements.  There should be some simple code that will iterate over the json file and produce an array of arrays that I could actually use for something.  I tried accessing it like an array: console.log(listAccounts[0]) but that returns undefined.  Do I need to stringify it or something?</p>