title: Getting data out of a JSON object in node js?
body: <p>I am trying to extract data from a JSON object by passing field names but then I get the undefined results when I try to extract data . For some reason the way I am getting the JSON Object is not the way I expected. What could be the error?</p>
  
  <p>JS code -</p>
  
  <pre><code>  function initfunc() {
                      $.ajax({
                          type: "POST",
                          contentType: "application/json; charset=utf-8",
                          url: "/dashboard",
                          data: JSON.stringify({country: country[counter], bankid: bankid[counter]}),
                          dataType: "json",
                          success: function (Result) {
                              Result = Result.Resultset
                              // console.log("result", Result);
  
  
                              //  console.log("result",Result);
                              var data = [];
                              var merchantname = [];
                              var successtranscs = [];
                              var failedtranscs = [];
                              var servicetranscs = [];
                              var bankname;
                              console.log("result",Result);
                              for(var i in Result) {
                                  merchantname.push(Result[i].MERCHANTNAME); // or .MERCHANTNAME?
                                  successtranscs.push(Result[i].NO_OF_SUCCESSFUL_TRANSACTIONS); // or .NO_OF_SUCCESSFUL_TRANSACTIONS?
                                  failedtranscs.push(Result[i].NO_OF_FAILED_BANK_TRANSACTIONS); // or .NO_OF_FAILED_BANK_TRANSACTIONS?
                                  servicetranscs.push(Result[i].NO_OF_FAILED_SERVICE_TRANSACTIONS); // or .NO_OF_FAILED_SERVICE_TRANSACTIONS?
                                  bankname = Result[i].BankName; // or .BankName?
                              }
                              //console.log("merchantname",merchantname);
                              StackedChart(bankname, merchantname, successtranscs, failedtranscs, servicetranscs);
                              merchantname = [];
                              successtranscs = [];
                              failedtranscs = [];
                              servicetranscs = [];
                              rows = null;
                              if (counter == country.length - 1) {
                                  counter = -1;
                                  counter++;
                              }
                              else {
                                  counter++;
                              }
                          }
                      });
  
  
  
  
  
                  }
  </code></pre>
  
  <p>server.js -</p>
  
  <pre><code>app.post('/dashboard', function (req, res) {
      cnn.TransactionInfo(req.body.country,req.body.bankid, function (err, result) {
          var resultset = {"Result":result};
          console.log(resultset);
  
          res.send({ Resultset : resultset });
  
  
      });
  });
  </code></pre>
  
  <p>Initial Result set from stored procedure - resultset-</p>
  
  <pre><code>{ Result:
     [ { BankName: 'IM BANK',
         MERCHANTNAME: 'MPesa',
         NO_OF_SUCCESSFUL_TRANSACTIONS: 29,
         NO_OF_FAILED_BANK_TRANSACTIONS: 0,
         NO_OF_FAILED_SERVICE_TRANSACTIONS: 4 },
       { BankName: 'IM BANK',
         MERCHANTNAME: 'Zuku',
         NO_OF_SUCCESSFUL_TRANSACTIONS: 1,
         NO_OF_FAILED_BANK_TRANSACTIONS: 0,
         NO_OF_FAILED_SERVICE_TRANSACTIONS: 0 },
       { BankName: 'IM BANK',
         MERCHANTNAME: 'BALANCE',
         NO_OF_SUCCESSFUL_TRANSACTIONS: 21,
         NO_OF_FAILED_BANK_TRANSACTIONS: 0,
         NO_OF_FAILED_SERVICE_TRANSACTIONS: 0 },
       { BankName: 'IM BANK',
         MERCHANTNAME: 'AIRTEL',
         NO_OF_SUCCESSFUL_TRANSACTIONS: 2,
         NO_OF_FAILED_BANK_TRANSACTIONS: 0,
         NO_OF_FAILED_SERVICE_TRANSACTIONS: 0 },
       { BankName: 'IM BANK',
         MERCHANTNAME: 'SAFARICOM',
         NO_OF_SUCCESSFUL_TRANSACTIONS: 4,
         NO_OF_FAILED_BANK_TRANSACTIONS: 0,
         NO_OF_FAILED_SERVICE_TRANSACTIONS: 0 },
       { BankName: 'IM BANK',
         MERCHANTNAME: 'FIXEDDEPOSIT',
         NO_OF_SUCCESSFUL_TRANSACTIONS: 1,
         NO_OF_FAILED_BANK_TRANSACTIONS: 0,
         NO_OF_FAILED_SERVICE_TRANSACTIONS: 0 },
       { BankName: 'IM BANK',
         MERCHANTNAME: 'FOREX',
         NO_OF_SUCCESSFUL_TRANSACTIONS: 1,
         NO_OF_FAILED_BANK_TRANSACTIONS: 0,
         NO_OF_FAILED_SERVICE_TRANSACTIONS: 0 },
       { BankName: 'IM BANK',
         MERCHANTNAME: 'KITSA2P',
         NO_OF_SUCCESSFUL_TRANSACTIONS: 1,
         NO_OF_FAILED_BANK_TRANSACTIONS: 0,
         NO_OF_FAILED_SERVICE_TRANSACTIONS: 0 },
       { BankName: 'IM BANK',
         MERCHANTNAME: 'STATEMENT',
         NO_OF_SUCCESSFUL_TRANSACTIONS: 2,
         NO_OF_FAILED_BANK_TRANSACTIONS: 0,
         NO_OF_FAILED_SERVICE_TRANSACTIONS: 0 },
       { BankName: 'IM BANK',
         MERCHANTNAME: 'TRANSFER',
         NO_OF_SUCCESSFUL_TRANSACTIONS: 1,
         NO_OF_FAILED_BANK_TRANSACTIONS: 0,
         NO_OF_FAILED_SERVICE_TRANSACTIONS: 0 } ] }
  </code></pre>
  
  <p>This is what I get after sending the data to my client script - The resultset becomes -</p>
  
  <pre><code>result:
  Object
  Result
  :
  Array[9]
  0
  :
  Object
  BankName
  :
  "IM BANK"
  MERCHANTNAME
  :
  "MPesa"
  NO_OF_FAILED_BANK_TRANSACTIONS
  :
  0
  NO_OF_FAILED_SERVICE_TRANSACTIONS
  :
  2
  NO_OF_SUCCESSFUL_TRANSACTIONS
  :
  25
  </code></pre>