Below is an example of the JSON structure I am working with:
{
"categories": [{
"type": "Fruits",
"items": [{
"name": "Apple"
}, {
"name": "Banana"
}, {
"name": "Orange"
}, {
"name": "Grapes"
}]
}]
}
I have successfully extracted the category Fruits
from this JSON and stored it in a new array. Now, I am trying to add the items under Fruits
such as Apple
, Banana
, and Orange
into the same array following the same hierarchical structure as the original JSON.
I attempted to use the categories[0].items.push
method to add the innermost item, but that has not been successful. I have already separated the values of the name
key from the JSON object and placed them in another array. I am seeking guidance on how to efficiently add these values to a new array while maintaining the original structure.