0

I have a collection of strings in an array. These strings are the JSON paths that i select from a checkbox tree.

var selected = ['a', 'b.c.0.d', 'b.c.1.d', 'b.c.0.e', 'b.c.1.e'];

I want to save it to the database with the real data given by the user. So i want to create a JSON object like following structure. It can be further nested.

    { 
       "a":5,
       "b":{ 
          "c":[ 
             { 
                "d":5,
                "e":5
             },
             { 
                "d":5,
                "e":5
             }
          ]
       }
    }

2
  • JSON is a textual notation for data exchange. (More here.) If you're dealing with JavaScript source code, and not dealing with a string, you're not dealing with JSON. Commented Jan 23, 2020 at 15:40
  • Welcome to Stack Overflow! Please take the tour (you get a badge!) and read through the help center, in particular How do I ask a good question? Your best bet here is to do your research, search for related topics on SO, and give it a go. If you get stuck and can't get unstuck after doing more research and searching, post a minimal reproducible example of your attempt and say specifically where you're stuck. People will be glad to help. Commented Jan 23, 2020 at 15:41

0

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.