I'm trying to extract all the key names from a JSON object, but I seem to be missing some when using the Object.keys method:
var myJSON = [
{
"Employees_Name": "Bill Sanders",
"Work_plan_during_my_absence": "Work from home",
"Assigned To-Manager Approval": [
"<a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="a8c5d1c5c9c6c9cfcddae8cfc5c9c1c486cbc7c5">[email protected]</a>"
],
"AbsenceVacation_Summary": [
{
"Computed_Leave_Days": 2,
"From_Date": "2018-08-20",
"To_Date": "2018-08-21",
"Id": "Shccbcc230_a30f_11e8_9afa_25436d674c51"
}
],
"Leave_Type": "Work from Home",
"Reporting_Manager": "My Manager",
"Total_Days": 2,
}
]
Although I tried accessing keys with Object.keys(), it only gave me the top-level ones. The nested keys are missing:
var keys_arr = Object.keys(myJSON[0]);
console.log(keys_arr);
The resulting array is as follows:
"[ 'Employees_Name', 'Work_plan_during_my_absence', 'Assigned To-Manager
Approval', 'AbsenceVacation_Summary', 'Leave_Type', 'Reporting_Manager',
'Total_Days']"
I suspect that looping through this list and checking if the value corresponds to an object or array might help solve this issue, but I'm unsure how to proceed. Any guidance would be greatly appreciated.