This might be a simple answer - but forgive me as I'm a noobie.
I'm trying to use dot notation to access nested json objects in results from a Google Custom Search engine (in Google Apps Script)
I have a variable result with my JSON file
var result = JSON.parse(response.getContentText());
and here is the relevant part of the JSON file :
"items": [
{
"kind": "customsearch#result",
"title": "Nicole Hartvig - Vice President Product Marketing - Zynga | LinkedIn",
"htmlTitle": "Nicole Hartvig - Vice President Product \u003cb\u003eMarketing\u003c/b\u003e - \u003cb\u003eZynga\u003c/b\u003e | LinkedIn",
"link": "https://www.linkedin.com/in/nicole-hartvig-77607ab",
"displayLink": "www.linkedin.com",
"snippet": "Nicole Hartvig. VP Product Marketing. ZyngaBar-Ilan University. San Francisco \nBay Area500+ connections.",
"htmlSnippet": "Nicole Hartvig. VP Product \u003cb\u003eMarketing\u003c/b\u003e. \u003cb\u003eZynga\u003c/b\u003eBar-Ilan University. San Francisco \u003cbr\u003e\nBay Area500+ connections.",
"formattedUrl": "https://www.linkedin.com/in/nicole-hartvig-77607ab",
"htmlFormattedUrl": "https://www.linkedin.com/in/nicole-hartvig-77607ab",
"pagemap": {
"metatags": [
{
"og:image": "https://static-exp1.licdn.com/sc/p/com.linkedin.public-profile-frontend%3Apublic-profile-frontend-static-content%2B1.0.796/f/%2Fpublic-profile-frontend%2Fartdeco-icons%2Fstatic%2Fimages%2Fghost-images%2Fperson.svg",
"og:type": "profile",
"twitter:card": "summary",
"twitter:title": "Nicole Hartvig - Vice President Product Marketing - Zynga | LinkedIn",
"al:ios:app_name": "LinkedIn",
"platform-worker": "https://static-exp1.licdn.com/sc/h/f1rrg2iyfxtin8sa39nl5yphl",
"og:title": "Nicole Hartvig - Vice President Product Marketing - Zynga | LinkedIn",
"al:android:package": "com.linkedin.android",
"pagekey": "public_profile_v3_mobile",
"locale": "en_US",
"al:ios:url": "https://www.linkedin.com/in/nicole-hartvig-77607ab",
"og:description": "View Nicole Hartvig’s profile on LinkedIn, the world's largest professional community. Nicole has 4 jobs listed on their profile. See the complete profile on LinkedIn and discover Nicole’s connections and jobs at similar companies.",
"al:ios:app_store_id": "288429040",
"platform": "https://static-exp1.licdn.com/sc/h/9jz7j4nt804mq3yk6akvsioxt,3wo0d340gqtz9xlexnrcz1as9",
"twitter:image": "https://static-exp1.licdn.com/sc/p/com.linkedin.public-profile-frontend%3Apublic-profile-frontend-static-content%2B1.0.796/f/%2Fpublic-profile-frontend%2Fartdeco-icons%2Fstatic%2Fimages%2Fghost-images%2Fperson.svg",
"al:android:url": "https://www.linkedin.com/in/nicole-hartvig-77607ab",
"profile:last_name": "Hartvig",
"twitter:site": "@Linkedin",
"viewport": "width=device-width, initial-scale=1.0",
"litmsprofilename": "public-profile-frontend",
"twitter:description": "View Nicole Hartvig’s profile on LinkedIn, the world's largest professional community. Nicole has 4 jobs listed on their profile. See the complete profile on LinkedIn and discover Nicole’s connections and jobs at similar companies.",
"profile:first_name": "Nicole",
"og:url": "https://www.linkedin.com/in/nicole-hartvig-77607ab",
"al:android:app_name": "LinkedIn"
}
],
"cse_image": [
{
"src": "https://static-exp1.licdn.com/sc/p/com.linkedin.public-profile-frontend%3Apublic-profile-frontend-static-content%2B1.0.796/f/%2Fpublic-profile-frontend%2Fartdeco-icons%2Fstatic%2Fimages%2Fghost-images%2Fperson.svg"
}
]
}
},
I'm trying to access certain values and put them into variables. Shorter dot notations work ok, but when I try and access data that is more deeply nested, I return null:
var linkedinURL = result.items[0].link;
Logger.log(linkedinURL); // returns linkedin URL perfectly
var fName = result.items[0].pagemap.metatags.profile:first_name;
Logger.log(fName); // returns null
Where am I going wrong?
Thank you so much