1

I want to create nested object in deeply way. What I'm trying to create is a grouped summary object from the array of nested JSON objects with the following structure:

[
    {
        "id": 1,
        "code": "193",
        "type": "Dental Provider",
        "classification": "Dentis",
        "specialization": "General Practice",
        "definition": "definition1",
        "notes": "[7/1/2003: new]",
        "individual": "individual"},
    {
        "id": 11,
        "code": "207",
        "type": "Allopathic & Osteopathic Physicians",
        "classification": "Anesthesiology",
        "specialization": "Pediatric Anesthesiology",
        "definition": "defin_2",
        "individual": "individual"}]

Expected:

result = {
    "invidual": {
        "Dental Provider": {
            "Dentis":{
                "General Practice":{
                    id: 1,
                    code: "193",
                    definition: "definition1",
                    individual: "individual",
                    type: "Dental Provider",
                    classification: "Dentist",
                    specialization: "General Practice"},
"invidual": {
        "Allopathic & Osteopathic Physicians": {
            "Anesthesiology":{
                "Pediatric Anesthesiology":{
                    id: 11,
                    code: "207",
                    definition: "defin_2",
                    individual: "individual",
                    type: "Allopathic & Osteopathic Physicians",
                    classification: "Anesthesiology",
                    specialization: "Pediatric Anesthesiology"}
}
1
  • 1
    Hi! 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 (there are hundreds of questions like this), 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 8, 2021 at 13:41

1 Answer 1

2
let result = taxonomies.reduce((c, v) => {
  c[v.individual] = c[v.individual] || {};                         
  c[v.individual][v.type] = c[v.individual][v.type] || {};   
  c[v.individual][v.type][v.classification] = c[v.individual][v.type][v.classification] || {};    
  c[v.individual][v.type][v.classification][v.specialization] = v
console.log(result)
Sign up to request clarification or add additional context in comments.

Comments

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.