I'm receiving a JSON object that looks similar to this and keep coming up with undefined when trying to get the employer name:
{
name: 'Freddy Krueger',
birthdate: 'March 16, 2015',
email: 'email@domain.com',
'employer[name]': 'Some Employer, Inc',
'employer[address]': '1428 Elm St. Springwood, OH 00666'
}
How am I supposed to access the employer data? obj.name, obj.birthdate, etc is no problem. But obj.'employer[name]' doesn't work, of course. I've tried every version I can think of obj.employer['name'] is no good, I get an error that says TypeError: Cannot read property 'name' of undefined Seems like something silly, but everything I google for only mentions using quotes in your values and such and brackets are for arrays. Nothing related to getting data that has single quotes and brackets in the name of the pair.
I've seen their structure, to match this, it would look like:
{
"name": "Freddy Krueger",
"birthdate": "March 16, 2015",
"email": "email@domain.com",
"employer": {
"name": "Some Employer, Inc",
"address": "1428 Elm St. Springwood, OH 00666"
}
}
There's more data, but this shows the part I'm having issues with. Sometimes, "employer" will have a phone, fax, email, website, etc in it as well. It still looks the same as my first example, just with the new pairs added as 'employer[whatever]': 'value'