Hi @fisblack ,
Welcome to the community.
Your transformation is kind of odd. Usually transformation is driven by existing values or structure even when generating new fields with defaults. I have never seen a case where newly generated values drive transformation of existing ones. I assume you are getting the list of courseSubCategory from somewhere and the script is rather dynamic utilizing some expression language & attributes. if you provide some context to how the list is coming about and what are you trying to achieve , maybe we can provide you with more accurate solution.
There are multiple ways of solving your problem as is - assuming you always want to replicate an existing field(s) against newly generated 3 elements array with default values of 1,2&3- , here is one of them:
[
{
"operation": "shift",
"spec": {
"*": "existing.&",
"#1|#2|#3": "courseSubCategory"
}
},
{
"operation": "shift",
"spec": {
"courseSubCategory": {
"*": {
"@(2,existing)": "[&1]",
"@": "[&1].courseSubCategory"
}
}
}
}
]
If you want to make this more dynamic in terms of number of "courseSubCatgory", you can construct the array assignment string "#1|#2|#3" in some upstream processors and store the value as flow attribute (let says its called the same) , then you can make it more dynamic by using the flowfile attribute where the assignment of the courseSubCategory in the first shift will look like this:
"${courseSubCategory}": "courseSubCategory"
Hope that helps. If it does help, please accept the solution.
Thanks