Я использовал рекурсию. Вот код:
var i=0
var properties={ "MainApplicant": {
"type": "object",
"title": "Main Applicant",
"properties": {
"birthDetails": {
"type": "object",
"title": "Birth Details",
"key": "birthDetails",
"properties": {
"dateOfBirth": {
"type": "string",
"title": "Date of Birth",
"key": "dateOfBirth",
"format": "date"
},
"countryOfBirth": {
"type": "string",
"title": "Country of Birth",
"key": "countryOfBirth",
},
}
}
}
}
}
function driller(data){
Object.keys(data).forEach(key=>{
//console.log(JSON.stringify(data[key]));
if(typeof(data[key])==='object'){
console.log(JSON.stringify(data[key]));
driller(data[key])
}
})
}
driller(properties)
А вот и вывод:
E:\Nodetest>node server.js
{"type":"object","title":"Main Applicant","properties":{"birthDetails":{"type":"object","title":"Birth Details","key":"birthDetails","properties":{"dateOfBirth":{"type":"string","title":"Date of Birth","key":"dateOfBirth","format":"date"},"countryOfBirth":{"type":"string","title":"Country of Birth","key":"countryOfBirth"}}}}}
{"birthDetails":{"type":"object","title":"Birth Details","key":"birthDetails","properties":{"dateOfBirth":{"type":"string","title":"Date of Birth","key":"dateOfBirth","format":"date"},"countryOfBirth":{"type":"string","title":"Country of Birth","key":"countryOfBirth"}}}}
{"type":"object","title":"Birth Details","key":"birthDetails","properties":{"dateOfBirth":{"type":"string","title":"Date of Birth","key":"dateOfBirth","format":"date"},"countryOfBirth":{"type":"string","title":"Country of Birth","key":"countryOfBirth"}}}
{"dateOfBirth":{"type":"string","title":"Date of Birth","key":"dateOfBirth","format":"date"},"countryOfBirth":{"type":"string","title":"Country of Birth","key":"countryOfBirth"}}
{"type":"string","title":"Date of Birth","key":"dateOfBirth","format":"date"}
{"type":"string","title":"Country of Birth","key":"countryOfBirth"}