I'm attempting to extract the "info" portion from the JSON data provided below. In my code snippet, I'm using the
<%= person['person_details']%>
to access that specific section of the JSON. However, it only returns [Object Object]. What I really want is to retrieve all the details in the info section of the JSON like: "Jim", "Bob", true, and "Two guys walk into a bar, one says: ow!". The challenge arises when some JSON objects have different fields (another example is added below). I've tried...
<%= person['person_details'][0][1]%>
But this throws an error. Removing the [1] results in an empty dropdown menu selection.
<div class="personForm">
<form>
Select Parameters
<select id="personIdList">
<% data1.forEach(function(person) {%>
<option><%= person['person_details']%>
<% }); %></option>
</select>
</form>
</div>
//JSON DATA TO BE EXTRACTED
"person_details": {
"info": {
"name": "Jim",
"lastName": "Bob",
"isMale": true,
"favJoke": "Two guys walk into a bar, one says: ow!"
}
},
//ANOTHER EXAMPLE
"person_details": {
"info": {
"email": "<a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="6b0904091806021f2b0c060a020745080406">[email protected]</a>",
"lastName": "tim",
"isMale": true,
"momMaidenName": "felicia"
}
},
//YET ANOTHER EXAMPLE (with 'information' instead of 'info')
"person_details": {
"information": {
"email": "<a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="096b666b7a64607d496e64686065276a6664">[email protected]</a>",
"lastName": "tim",
"isMale": true,
"momMaidenName": "felicia"
}
},