Navigate through the JSON object and generate all possible combinations of nested elements

Here is a JSON object that I need to iterate through in order to generate all possible nested group names:

{
    "groups": [
        {
            "group": "group1",
            "childrens": [
                {
                    "group": "group1_1",
                    "childrens": []
                },
                {
                    "group": "group1_2",
                    "childrens": [
                        {
                            "group": "group1_2_1",
                            "childrens": []
                        },
                        {
                            "group": "group1_2_2",
                            "childrens": []
                        },
                        {
                            "group": "group1_2_3",
                            "childrens": []
                        }
                    ]
                },
                {
                    "group": "group1_3",
                    "childrens": []
                },
                {
                    "group": "group1_4",
                    "childrens": []
                }
            ]
        },
        {
            "group": "group2",
            "childrens": [
                {
                    "group": "group2_1",
                    "childrens": []
                },
                {
                    "group": "group2_2",
                    "childrens": []
                }
            ]
        }
    ]
}


Q) how to genarete the below list from above JSON
  group1
  group1/group1_1
  group1/group1_2
  group1/group1_2/group1_2_1
  group1/group1_2/group1_2_2
  group1/group1_2/group1_2_3
  group1/group1_3
  group1/group1_4
  group2
  group2/group2_1
  group2/group2_2

The provided JSON object needs to be iterated through to obtain all possible nested group names.

Answer №1

Do you think a solution similar to this would be effective?

for(var key in OBJECT){
   process(OBJECT[key]);
}

function process(item){

    for(var key in item){
       if(typeof item[key] == "object"){
           process(item[key]);
       }else{
           performAction();
       }
    }

    var performAction = function(){
       ///// PERFORM SPECIFIC ACTION
    }

}

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Incorporating additional ES6 modules during the development process

As I build a React component, I find that it relies on an ES6 component that I'm currently developing. Since I created the latter first, what is the typical method to include it during development as I work on the second component? If the dependency w ...

Clear the local storage once the URL's view has been fully loaded

When retrieving details of a specific item by passing URL parameters stored in local storage, I encountered an issue. I need to delete the local storage variables after the view is loaded. However, what actually happens is that the local storage variable ...

What is the best way to retrieve ember model relation properties within routes and controllers?

Currently using ember 2.7.0, I am facing an issue while setting up my ember app with a currentUser.organization derived from the authenticated token. Although I can successfully resolve the currentUser, I am encountering difficulties in resolving the prope ...

Tips to successfully save and retrieve a state from storage

I've encountered a challenge while working on my Angular 14 and Ionic 6 app. I want to implement a "Welcome" screen that only appears the first time a user opens the app, and never again after that. I'm struggling to figure out how to save the s ...

"Implementing a full page refresh when interacting with a map using

Here is an example of how I display a map on the entire page: <div id="map_canvas"> </div> UPDATE 2: I have successfully displayed a menu on the map, but there is a problem. When I click on the button, the menu appears briefly and then disapp ...

What causes the console.log function to behave in this manner?

When using the node.js interpreter, if you run the code: console.log("A newline character is written like \"\\ n \"."); //output will be:- // A newline character is written like "\ n ". However, if you just enter the following in ...

Is there a method to verify the sequential loading of JavaScript files?

It has come to my understanding that in the case of having two JS files (x.js and y.js), where y.js uses functions from x.js, it is important to load x.js before y.js when loading the files. For larger projects, I am curious if there are tools available s ...

Processing Data with JavaScript

I am new to working with JavaScript, coming from the Python world. I need some assistance. Currently, I am retrieving data from the back end that has the following structure: { "Airports": { "BCN": { "Arrivals": [ ...

Retrieve the URI data from the response object using Axios

Currently, I'm in the process of transitioning a node project from utilizing request.js to incorporating axios.js While using the request package, extracting URI data from the response object can be achieved like so: request(req, (err, response) =&g ...

I was unable to produce the result of the input value entered at the bottom

Is there a way to view the input and output simultaneously in my project? I've seen this done using a button, but I'm looking to achieve the same without a button. How can I do this? <input type="text" id="myText"> <b ...

Is there a way to extract data from a JSON/gSON Object using jqGrid?

I need assistance in adding data from a Java Object to a jqGRID Table using gSON for JSON encoding. However, I am facing a challenge in configuring the jsonreader. Here is an example of the Java Object structure: public class UserObject { public int ...

How to Generate a Doughnut Graph with JSON and the chart.js Library

Exploring chart.js for analytics is a new experience for me. I've been searching online for a comprehensive guide on how to pass JSON data from an SQL Database using LINQ Lambda expression into chart.js within a .NET environment. Unfortunately, I have ...

Tips for Waiting for Binding in an Angular 1.5 Component (No Need for $scope.$watch)

Currently, I am in the process of developing an Angular 1.5 directive and have encountered a frustrating issue related to manipulating data that is not yet available. Below is a snippet of my code: app.component('formSelector', { bindings: { ...

Display an image in response to a button click using JavaScript

I am currently working on a feature that will display information when a radio button is pressed. I also want to include an image, but I am facing an issue where the text displays correctly but the image does not appear. What steps should I take to resolve ...

Updating the value of each preceding sibling of every checked checkbox using jQuery upon form submission

After extensive research, I discovered that the most effective approach involves using a clever workaround to capture every tick and untick on a dynamic input row with multiple checkbox arrays. However, none of the solutions provided a viable method. I th ...

Troubleshooting Problems with Promises in Node.js Express

I am currently developing a Node.JS/Express application with Jade as the template engine, but I am encountering some unexpected behavior. The issue arises when trying to retrieve data from a mock API and pass it to my Jade template. Despite confirming tha ...

Unleashing the Power of RxJS with OR Conditions

I am working with two Observables. For instance, I am waiting for either an HTTP POST call or a WebSocket call to return so that I can proceed. Once either call returns, I need to verify the information until a certain condition is met. In the following e ...

Rest API question: Based on the output provided, how should the URL format be correctly written?

If I were in charge of developing a rest api that generated the following result from the given URL: /owner/123/animal {     {       Owner: 123,       Animal: Cat     },     {       Owner: 123,       Animal: Dog     },     {   ...

Spinning text within a circular rotation in CSS

Looking for guidance on how to center the "hallo" text inside a circle? Currently experiencing issues with the circle display in IE8 and Firefox. Any suggestions on how to fix this would be greatly appreciated. And here is the link to my code snippet: CSS ...

What is the best way to conceal a bootstrap directive tooltip in Vue.js for mobile users?

Currently, I'm tackling a project with Vuejs and Laravel. There's a tooltip directive incorporated that relies on Bootstrap's functionality. Check it out below: window.Vue.directive("tooltip", function(el, binding) { // console ...