このjsonを配列としてフラットにしたい.Any help pls


let json = [ {

    "name":"vay",

    "age":26,

    "children":[

         {"name":"Ajay",

          "age":16,

          "children":[

              {

            "name":"kojay",

            "age":26,

            "children":[

                {

                    "name":"dija",

                    "age":"4"

                }

            ]

         }

          ]

         },

         {

            "name":"kojay",

            "age":26,

            "children":[

                {

                    "name":"dija",

                    "age":4

                }

            ]

         }

    ]

}]

`let 配列=[]

関数 r(json){

for(let i=0;i<json.length;i++){

array.push(json[i])

  function e(jso){

    if(json[i].children!=null){

        json[i].children.map((x)=>array.push(x))

    }

}

e(json[i])



}

}
`