Skip to content
Advertisement

Nested Tree structure object trying to extract and get information Json object

I would like to know the correct way to create a nested Json tree Structure object in javascript. data structure containing objects and arrays. How can I extract the information, i.e. access a specific or multiple values (or id)?

I have a very deep nested tree structure Json and I am given an object that can exist at any depth. I need to be able to iterate through all grandparent / parent / children nodes until I find the requested category, plus be able to capture its grandparent / parent / children categories all the way through.

//input data structure

JavaScript

//output

JavaScript

Advertisement

Answer

Here is the code. You have the result in output variable:

JavaScript
User contributions licensed under: CC BY-SA
10 People found this is helpful
Advertisement