Loading
Know the answer? Post it. Somebody with the same question will find it here.
Answer a question in the forums and earn +20 SHARP for every answer.
See unanswered questions
DevSocialUpcoming · 3rd editionAI Agents ConferenceDec 1–3, 2026Live onlineFree to attend5days leftRegister
Sachin SinghRank #66 · 26.2K reputationPosted Jun 22, 2021, 12:03 PM EDT
there is a simple rule of thumb.
1. you can not get JSON value directly, so convert it into a javascript object, using Json.parse();
2. Javascript objects are accessed by dot (.)
3. Arrays are accessed by index ex:- array[1].
now apply that.
const txt = `{ "prop1": "John Doe", "prop2": 35, "prop3": { "prop4": { "prop5": "Susan", "prop6": 32 }, "prop7": [ { "prop8": "Alex", "prop9": 5, "prop10": "dancing" } ] }, "prop11": [ { "prop12": "BMW X5", "prop13": 2015 }, { "prop14": "Tesla Model S", "prop15": 2018 } ] }` const obj = JSON.parse(txt); var prop8Value = obj.prop3.prop7[0].prop8 ; // AlexSatya KarkiRank #78 · 24.6K reputationPosted Jun 22, 2021, 1:51 PM EDT
Rijwan AnsariRank #82 · 24.2K reputationPosted Jun 22, 2021, 1:55 PM EDT
Sachin SinghRank #66 · 26.2K reputationPosted Jun 22, 2021, 10:26 AM EDT
Kiran MaramRank #1,166 · 1.5K reputationPosted Jun 22, 2021, 10:30 AM EDT
{
"prop1": "John Doe",
"prop2": 35,
"prop3": {
"prop4": {
"prop5": "Susan",
"prop6": 32
},
"prop7": [
{
"prop8": "Alex",
"prop9": 5,
"prop10": "dancing"
}
]
},
"prop11": [
{
"prop12": "BMW X5",
"prop13": 2015
},
{
"prop14": "Tesla Model S",
"prop15": 2018
}
]
}
From the above JSON I want to pick a value of prop8, how can I get?