0

Is there a way to parse a string as a chain of keys in a JSON dictionary?

For example, consider the below dictionary:-

person :{
 attributes : {
   gender: "F",
   height: 5.9,
   ...
 },
 functions : {
   eat : {
     enabled: true
     likes : ['pizza','ice-cream']
     dislikes : []
   },
   ...
 }
}

If I provide the keystring as

keystring="functions.eat.enabled"

Can I print the value from dictionary like below:

console.log(person[keystring]);
>> true

0 Answers0