I have a simple input json object that I would like to turn into an array of json objects, with the number of objects being equal to the number of attributes and each object inheriting one specific attribute. My input looks as follows:
{
"id": "00abc",
"attribute1": 100,
"attribute2": "yes",
"attribute3": false,
"attribute4": "up"
}
My desired output would look like this:
{
"array" : [ {
"id" : "00abc",
"repeatedId" : "00abc"
}, {
"attribute1" : 100,
"repeatedId" : "00abc"
}, {
"attribute2" : "yes",
"repeatedId" : "00abc"
}, {
"attribute3" : false,
"repeatedId" : "00abc"
}, {
"attribute4" : "up",
"repeatedId" : "00abc"
} ]
}
I have managed to almost get there using the following spec:
[
{
"operation": "shift",
"spec": {
"#array": {
"*": {
"@(2,id)": "&2[#2].repeatedId",
"@2": {
"*": "&3.[#2].&"
}
}
}
}
}
]
Unfortunately, the spec always produces arrays of the values for every key, i.e. this is the output I’m getting:
{
"array" : [ {
"repeatedId" : "00abc",
"id" : [ "00abc", "00abc", "00abc", "00abc", "00abc" ]
}, {
"attribute1" : [ 100, 100, 100, 100, 100 ],
"repeatedId" : "00abc"
}, {
"attribute2" : [ "yes", "yes", "yes", "yes", "yes" ],
"repeatedId" : "00abc"
}, {
"attribute3" : [ false, false, false, false, false ],
"repeatedId" : "00abc"
}, {
"attribute4" : [ "up", "up", "up", "up", "up" ],
"repeatedId" : "00abc"
} ]
}
I am unsure how to simply get the value instead of an array on the RHS. Any help is appreciated!
Edit: as you can see inheriting the attribute works fine, I should note.