I have a JSON input where:
- acceptIds is an array containing some IDs.
- phoneNumbers is an array of objects.
- Some objects inside phoneNumbers contain an accept object but are missing the acceptId field.
- The number of IDs in acceptIds is always equal to the number of accept objects missing acceptId.
I need a JOLT transformation to assign values from acceptIds to acceptId only where it is missing, while keeping the rest of the structure unchanged.
Example Input:
{
"acceptIds": [
"23"
],
"phoneNumbers": [
{
"phoneNumber": "123",
"accept": {
"acceptId": "1",
"acceptName": "phone"
}
},
{
"phoneNumber": "456"
},
{
"phoneNumber": "789",
"accept": {
"acceptName": "phone"
}
}
]
}
Expected Output:
{
"phoneNumbers": [
{
"phoneNumber": "123",
"accept": {
"acceptId": "1",
"acceptName": "phone"
}
},
{
"phoneNumber": "456"
},
{
"phoneNumber": "789",
"accept": {
"acceptId": "23",
"acceptName": "phone"
}
}
]
}
Requirements:
acceptIds should only be used for objects where accept.acceptId is missing. The order of acceptIds should be maintained while filling the missing values. If an object does not have an accept object, it should remain unchanged. How can I achieve this using JOLT transformation?