1

I have a json array which im getting my react data from it, the json is like this:

 {
         "Folders": [
           {
             "name": "parent 2",
             "children": [        //this is children_1
                {
                  "name": "parent 2",
                  "id": "parent 2",
                  "children": []     //this is children_2
                 }
               ],
               "id": 1
            }
          ]
        }

lets say i have the key value of name inside children(children_1) and i want to get the rest of the data inside that children using the name that i have, is there a way to do that ?

2
  • 1
    Welcome to SO. You might find reading the site help section useful when it comes to asking a good question, and this question checklist. Code that you have worked on to solve the problem should include a minimal reproducible example, and be included in your question. Commented Dec 27, 2021 at 4:37
  • I tried to edit it so its fully understandable, so where is the problem? Commented Dec 28, 2021 at 5:13

1 Answer 1

1

Look at jsonpath

so it will be

var json = require('jsonpath');
var names = jp.query(json, '$.Folders[*].children[*].children');

Sign up to request clarification or add additional context in comments.

4 Comments

cant really get it to work
what is your data you are referring to ? Did I understand correct that you need get all from deepest children list ?
i have the value "name" inside (children_1), and i want to get the rest of the values inside (children_1), using that name.(something like finding the name with its value and then getting the parent).
something like this jp.query(json, '$.Folders[*].children[?(@.name === "parent 2")].children') ? please read npm documentation

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.