title: Iterating through a nested JSON object
body: <p>I'm having trouble trying to get my nested object to loop. The issue is it doesn't even hit the loop, like there's no values to loop through. I've looked through several posts and tried what they had to say and it's not even making it into the loop. Below is the code i'm using, any help would be awesome. </p>
  
  <pre><code>// json string being parsed
  var objString = '{ "error": "no crontab for ec2-user "}}{ "accounts" : { "demo": { "Name": "Your Medical Clinic", "groupid": "demo", "CallerID": "8664738160", "CallerID_err": "OK", "TransferPhone": "1-931-555-1212", "TransferPhone_err": "INVALID LENGTH", "TimeZone": "EST", "EMRSoftware": "Greenway", "merlin": 1, "prm": 1, "CallDaysOut": 2, "EmailDaysOut": 5, "enablevoice": 1, "enabletext": 1, "enablemail": 1, "Exclude": "12 Months,12-17 Years,18+ Years,2 Months,", "emailBtnConfirm": 1, "emailBtnReschedule": 1, "emailBtnCancel": 1, "enablenoshow": 1, "enablecollection": 0, "enablerecall": 1, "enableapptalert": 1, "AppendCallerID": "Confirm,Cancel,Resched,AnsMach", "EmailReport": "kevin@relatient.net,john@relatient.net,hello@gim.com", "EmailReport_err": "OK", "SurveyReport": "chris@relatient.net", "SurveyReport_err": "OK", "HMReport": "john@relatient.net,kevin@relatient.net", "HMReport_err": "OK", "ApptReminders" : { "cronCalls": { "cronCalls_570": { "StartHour": 18, "StartQtrHour": 0, "StartTime_local": "7:00 PM EST", "EndHour": 19, "EndQtrHour": 0, "EndTime_local": "8:00 PM EST", "CallDays": "MoTuWeThFr" } }, "cronEmail": { "cronEmail_110": { "hour": 18, "qtrhour": 99, "StartTime_local": "INVALID EST", "ApptTimeMath": "", "EmailDays": "MoTuWeThFr" } }, "cronSMS": { "cronSMS_82": { "hour": 7, "qtrhour": 0, "StartTime_local": "8:00 AM EST", "DaysOut": 0, "cronargid": 1, "cronargid_type": "frombulk", "ApptTimeMath": "", "WorkDays": "MoTuWeThFr", "SendOnDays": "TuWeThFr", "cronSMS_err": "OK" } } }, "HealthMaint" : { "cronHMCalls": { "cronHMCalls_2": { "StartHour": 12, "StartQtrHour": 0, "StartTime_local": "1:00 PM EST", "EndHour": 16, "EndQtrHour": 0, "EndTime_local": "5:00 PM EST", "ActiveDays": "MoTuWeFrSa" } }, "cronHMEmail": { "cronHMEmail_1": { "hour": 3, "qtrhour": 3, "StartTime_local": "4:45 AM EST", "ActiveDays": "ThFrSa" } }, "cronHMSMS": { "cronHMSMS_1": { "hour": 2, "qtrhour": 2, "StartTime_local": "3:30 AM EST", "ActiveDays": "SuTuThSa" } } }, "MDPay" : { "cronMDPayCalls": { "cronMDPayCalls_2": { "hour": 15, "qtrhour": 3, "StartTime_local": "4:45 PM EST", "ActiveDays": "MoWeFr" } }, "cronMDPayEmail": { "cronMDPayEmail_2": { "hour": 13, "qtrhour": 1, "StartTime_local": "2:15 PM EST", "ActiveDays": "MoFr" } }, "cronMDPaySMS": { "cronMDPaySMS_2": { "hour": 15, "qtrhour": 1, "StartTime_local": "4:15 PM EST", "ActiveDays": "Su" } } }, "NoShow" : { "cronNoShowCalls": { } }, "Recall" : { "cronRecallCalls": { "cronRecallCalls_4": { "Hour": 11, "QtrHour": 0, "StartTime_local": "12:00 PM EST", "ActiveDays": "MoTuWeThFr" } } }, "cronEmailReports": { "cronEmailReport_155": { "hour": 20, "qtrhour": 1, "StartTime_local": "9:15 PM EST", "DaysOut": 4, "csv": 1, "reportargid": 3, "reportargid_type": "calltime", "WorkDays": "SuMoTuThFrSa", "SendOnDays": "MoTuWeThFr" } }, "CallCntNotStatus99": 3680, "crontab": { }, "IncomingFiles": { "file_1": "payments.json", "file_1_changed": "2015-04-08 10:44", "file_1_lines": 222, "file_2": "recall.csv", "file_2_changed": "2014-04-17 08:58", "file_2_lines": 0, "file_3": "elerts.txt", "file_3_changed": "2014-12-11 14:14", "file_3_lines": 21, "file_4": "noshow.csv", "file_4_changed": "2014-04-17 08:44", "file_4_lines": 0, "file_5": "daily.txt", "file_5_changed": "2014-10-29 12:50", "file_5_lines": 188, "file_6": "bulk.csv", "file_6_changed": "2014-10-20 14:41", "file_6_lines": 1 } } }}';
  </code></pre>
  
  <p>Function looping through object</p>
  
  <pre><code>// example code to loop through object
  var jsontext = objString.replace('{ "error": "no crontab for ec2-user "}}', '').trim(),
      obj = JSON.parse(jsontext);
  
  console.log(obj);
  
  if(typeof obj !== 'object') console.log('error'); return false;
  
  // top level loop
  $.each(obj, lp);
  
  function lp(key, val) {
      // render table
      console.log(key);
      console.log(val);
  
      // recursion for children
      if(val !== null &amp;&amp; typeof val === "object") 
          $.each(val, lp);
  }
  </code></pre>
  
  <p><a href="http://jsfiddle.net/trickell/keqk2aya/" rel="nofollow" title="Demo Fiddle">Demo Fiddle</a></p>