For the details mentioned below, I would like to move the email.values* to payload.*.content.values (preserving the changes)
I have created below Jolt –
[
{
"operation": "shift",
"spec": {
// set values of the object keys to their accountIds
// while taking out the value of request.body.inputAccountId
"*": {
"request": {
"body": {
"inputId": "inputId",
"service": "sName"
}
},
"*": {
"@": "@2,accountId.&"
}
}
}
},
{
"operation": "shift",
"spec": {
"*": {
"@2,&": {
"familyRole": {
"//": "Comment: Based on Family role get the details, familyRole1=Organizer, familyRole2=Guardian, familyRole3=child",
"1|2": {
"@(2,accountId)": "payload.@(3,accountId).accountId",
"@(2,locale)": "payload.@(3,accountId).content.locale",
"@(2,onlineId)": "payload.@(3,accountId).content.values.onlineId",
"@(2,emailAddresses)": {
"*": {
"isMain": {
"true": {
"@(2,address)": "payload.@(7,accountId).destination.emailAddress"
}
}
}
},
"@(5,sName)": "payload.@(3,accountId).content.values.sName"
}
}
}
},
"inputId": {
"*": {
"@2,&": {
"onlineId": "..payload.childId"
}
}
}
}
}
]
For given input –
[
{
"request": {
"body": {
"inputId": "2211",
"service": "trial"
}
}
},
{
"accountId": "1234",
"role": 1,
"gender": "f",
"signinId": "[email protected]",
"onlineId": "one"
},
{
"accountId": "1122",
"role": 2,
"gender": "f",
"signinId": "[email protected]",
"onlineId": "two"
},
{
"accountId": "2211",
"role": 3,
"gender": "f",
"signinId": "[email protected]",
"onlineId": "three"
}
]
It gives me below output –
{
"payload" : {
"childId" : "three",
"1234" : {
"accountId" : "1234",
"content" : {
"values" : {
"onlineId" : "one",
"sName" : "trial"
}
}
},
"1122" : {
"accountId" : "1122",
"content" : {
"values" : {
"onlineId" : "two",
"sName" : "trial"
}
}
}
}
}
Expected output:
{
"payload" : {
"1234" : {
"accountId" : "1234",
"content" : {
"values" : {
"onlineId" : "one",
"cOnlineId" : "three",
"sName" : "trial",
}
}
},
"1122" : {
"accountId" : "1122",
"content" : {
"values" : {
"onlineId" : "two",
"cOnlineId" : "three",
"sName" : "trial"
}
}
}
}
}
Now I just need help to figure out how can I add that childId in payload.*.content.values ?
I have applied multiple combinations in JOLT Spec but it didn’t works, Please suggest. I also referred this -https://stackoverflow.com/questions/76474146/how-to-insert-json-object-in-nested-json-using-jolt-spec
2
Answers
I was finally able to solve this.
Earlier, I was trying to update the existing payload and then traverse the tree to move the childId which was coming in the later operation. However, now -
Below is my updated JOLT-
You can use the following transformation specs as an alternative option :