I have the following JSON data structure. I would like to know how could I extract the data providing the keys.
"Meta Data": {
"1. Information": "High School",
"2. Name": "St Marys"
},
"Teachers' Names": {
"Grade I": {
"1. English": "Amanda Fernandez",
"2. Sociology": "Christina Andrew",
"3. Applied Science": "George Binu"
},
"Grade II": {
"1. English": "Gedfd Hkdfd",
"2. Sociology": "lksdg klsdfd",
"3. Applied Science": "some one else"
}
}
}
I use nodejs and get this data in a 'body' object under request module. How do I extract the Grade I, English Teacher name above? I tried body["Teachers' Names][0] to see if it would give me at least the Grade I object in full. But it didn't. Can someone please help me?
bodyalways in the same structure or is it generated dynamically?Object.keysor an "for..in" loop to go trough the properties. If you want one specific value you shouldn't loop trough all the properties of the object.breakso you'll only read the first property. See this jsfiddle for an example: jsfiddle.net/esrm9bc0