I have a JSON file with nested objects, I need to extract a specific key's value from each object and save to an array. No need to preserve the structure or order.
Please see JSON below. I need to extract the values of the 'text' key and have a resulting array like this
["CPUs", "AMD", "Ryzen", "intel",....]
What is the best way to achieve this?
[
{
"itemID":"1",
"items":[
{
"itemID":"2",
"items":[
{
"itemID":"3",
"items":[
{
"itemID":"15",
"text":"Ryzen"
},
{
"itemID":"16",
"text":"Threadripper"
}
],
"text":"AMD",
},
{
"itemID":"66",
"items":[
{
"itemID":"76",
"text":"i5"
},
{
"itemID":"77",
"text":"i7"
},
{
"itemID":"78",
"text":"i3"
}
],
"text":"Intel"
},
{
"itemID":"70",
"text":"Apple"
}
],
"text":"CPUs"
}
],
"text":"computer parts"
},
{
"itemID":"4",
"items":[
{
"itemID":"5",
"items":[
{
"itemID":"21",
"text":"porsche"
},
{
"itemID":"22",
"text":"maserati"
},
{
"itemID":"23",
"text":"ferrari"
}
],
"text":"sports cars"
}
],
"text":"cars"
}
]