CodingIsFun33
CodingIsFun33

Reputation: 453

How to access a json object inside another json object inside another object?

So I basically I have a json object that inside of it has a json object called "from". Then from has a json object inside of it called value, then inside of value is address. I am trying to access address here:


        let data = doc.data();
                const email = JSON.parse(data.Emails[z]);

                let emailBody = email.body;
                let emailSubject = email.subject;
                let oldDate = email.date;
                let emailFrom = email.from.value.address;


in the emailFrom variable. I thought email.from.value.address would do the trick but it does not seem to be working.

currently email.from allows me to access the from object but I am trying to figure out how to access value and then address as well with it. Here is an example of the from json object as well


,"from":{"value":[{"address":"admin@removed","name":"World Cafe"}],"html":"<span class=\"mp_address_group\"><span class=\"mp_address_name\">W World Cafe</span> &lt;<a href=\"mailto:[email protected]\" class=\"mp_address_email\">admin@removed</a>&gt;</span>","text":"World Cafe <[email protected]>"}}"

hoping someone can point me in the right direction here, thanks so much =]

Upvotes: 1

Views: 2103

Answers (3)

Arjun Singh
Arjun Singh

Reputation: 312

In your json object, the type of property email.from.value is array and array values can be accessed by its index. Try this:

let emailFrom = email.from.value[0].address;

Upvotes: 1

morphen
morphen

Reputation: 76

you need to do something like this email.from.value[0].address as you are storing an array in value. Hope this helps.

Upvotes: 1

Kiran Shinde
Kiran Shinde

Reputation: 5982

Like

email.from.value[0].address

As value is array you have to specify index.

Upvotes: 2

Related Questions