I need a transformation that shifts data from one array to another directly. My main problem is that the input dependant
array might be empty sometimes. For those cases, there is a master
array which defines the length of the result
array.
To sum things up, I need to:
dependant
to result
.master
array length if no data was shifted.A couple of examples:
Input:
{
"master": [
{
"a": "a1",
"b": "b1"
},
{
"a": "a2",
"b": "b2"
}
],
"dependant": [
{
"data": "AA"
},
{
"data": "BB"
}
]
}
Desired output:
{
"result": [ "AA", "BB" ]
}
dependant
array is empty and we need to create the result
array with the same length as master
. Each element can be any string such as DEFAULT
.
Input:
{
"master": [
{
"a": "a1",
"b": "b1"
},
{
"a": "a2",
"b": "b2"
}
],
"dependant": []
}
Output:
{
"result": [ "DEFAULT", "DEFAULT" ]
}
You can consecutively apply modify-overwrite-beta and shift transformations such as
[
{
"operation": "modify-overwrite-beta",
"spec": {
"szdependant": "=size(@(1,dependant))"
}
},
{
"operation": "shift",
"spec": {
"szdependant": {
"0": {
"@(2,master)": { "*": { "#DEFAULT": "result" } }
},
"*": {
"@(2,dependant)": { "*": { "*": "result" } }
}
}
}
}
]
in order to use the size value(szdependant
) of the dependant
list as a conditional statement within the shift transformation step