I want to use a jolt transformation to add an element to an array.
My approach is to use default to append to the last element in the array
Input
{
"options": [
{
"name": "Will",
"state": "enabled"
},
{
"name:": "Bert",
"state": "enabled"
},
{
"name": "Kate",
"state": "disabled"
}
]
}
Jolt Spec
[
{
"operation": "default",
"spec": {
"options[]": {
"3": {
"name": "Bob",
"state": "enabled"
}
}
}
}
]
Desired Output
{
"options": [
{
"name": "Will",
"state": "enabled"
},
{
"name": "Bert",
"state": "enabled"
},
{
"name": "Kate",
"state": "disabled"
},
{
"name": "Bob",
"state": "enabled"
}
]
}
It works if the input array length is 3. How can I obtain the array length and set the index dynamically?