I want to rename keys in an object, that contains children objects that look the same.
This is my starting object:
objs = {
"one":{
"title":"bla",
"amount":5,
"children":[
{
"title":"bla",
"identifier":"some text"
},
{
"title":"bla2",
"identifier":"some text2"
}
]
},
"two":{
"title":"bla",
"amount":5,
"children":[
{
"title":"bla",
"identifier":"some text"
},
{
"title":"bla2",
"identifier":"some text2"
}
]
}
}
and I want it to transform it into this:
objs = {
"one":{
"text":"bla",
"amount":5,
"items":[
{
"text":"bla",
"identifier":"some text"
},
{
"text":"bla2",
"identifier":"some text2"
}
]
},
"two":{
"text":"bla",
"amount":5,
"items":[
{
"text":"bla",
"identifier":"some text"
},
{
"text":"bla2",
"identifier":"some text2"
}
]
}
}
So basically I want to rename every key children
to items
and every key title
to text
, no matter how deep the object children go. I already tried using spread & Destructuring Assignment
in foreach loops but it did not work very well..