I have a problem writing objects to an array. Basically I want to merge the arrays and rename the fields, while keeping the objects seperately.
My input json looks like this:
{
"board":[
{
"role":"Head of board",
"id":"111",
"name":"John Snow"
}
],
"leaders":[
{
"role":"Accounting leader",
"id":"222",
"name":"Amanda Johns"
},
{
"role":"HR leader",
"id":"333",
"name":"Frank Smith"
}
]
}
This is my spec: (I am aware that the values in brackets are probably not right)
[
{
"operation":"shift",
"spec":{
"board":{
"*":{
"id":"employees.bosses[#2].emp_num",
"role":"employees.bosses[#2].position",
"name":"employees.bosses[#2].name"
}
},
"leaders":{
"*":{
"id":"employees.bosses[#2].emp_num",
"role":"employees.bosses[#2].position",
"name":"employees.bosses[#2].name"
}
}
}
}
]
and this is my output:
{
"employees": {
"bosses": [ {
"emp_num": ["111", "222"],
"position": ["Head of board", "Accounting leader"],
"name": ["John Snow", "Amanda Johns"]
}, {
"emp_num": "333",
"position": "HR leader",
"name": "Frank Smith"
} ]
}
}
while I expect output that looks like this:
{
"employees": {
"bosses": [ {
"emp_num": "111",
"position": "Head of board",
"name": "John Snow"
}, {
"emp_num": "222",
"position": "Accounting leader",
"name": "Amanda Johns"
}, {
"emp_num": "333",
"position": "HR leader",
"name": "Frank Smith"
} ]
}
}
I have major troubles understanding what to do and how the [#n] work, I would really appreciate any help with fixing my spec and explaination why this does/does not work!