Created 12-14-2023 01:54 AM
Hii Everyone,
I've been struggling to achieve the desired result with a Jolt transformation for the past few days and could really use some help from the community.
input.json:
{
"email": "abcmail@gmail.com",
"dates": [
{
"date": "2023-12-01",
"type": "full"
},
{
"date": "2023-11-03",
"type": "full"
},
{
"date": "2023-11-02",
"type": "full"
},
{
"date": "2023-10-01",
"type": "half"
}
]
}
output.json
[
{
"emailId": "abcmail@gmail.com",
"date": "2023-12-01",
"type": "full"
},
{
"emailId": "abcmail@gmail.com",
"date": "2023-11-03",
"type": "full"
},
{
"emailId": "abcmail@gmail.com",
"date": "2023-11-02",
"type": "full"
},
{
"emailId": "abcmail@gmail.com",
"date": "2023-10-01",
"type": "half"
}
]
spec file for the transformation:
[
{
"operation": "shift",
"spec": {
"*": {
"email": "[].emailId",
"dates": {
"*": {
"date": "[&1].date",
"type": "[&1].type"
}
}
}
}
}
]
Despite my efforts, I'm not achieving the expected outcome. Can anyone please review my Jolt specification and provide insights on what might be going wrong? Your assistance is highly appreciated.
Thank you in advance!
Created 12-14-2023 05:54 AM
Hi @Eva0 ,
You were close . I think the first astrik "*" was not needed because the input json is not contained in an array brackets. Then to include the email in each data element it has to be added at the date & type level but to reference the value you need to go to 2 levels up using the @ character as in @(2,mail) where the email is located in relative to date & type.
[
{
"operation": "shift",
"spec": {
//level 2 where email originally is
"dates": {
// level 1
"*": {
// start count here at level 0
"@(2,email)": "[&1].email",
"date": "[&1].date",
"type": "[&1].type"
}
}
}
}
]
If you find this helpful please accept solution.
Thanks
Created 12-14-2023 05:38 AM
@Eva0, Welcome to our community! To help you get the best possible answer, I have tagged our NiFi experts @MattWho @TimothySpann @cotopaul @SAMSAL who may be able to assist you further.
Please feel free to provide any additional information or details about your query, and we hope that you will find a satisfactory solution to your question.
Regards,
Vidya Sargur,Created 12-14-2023 05:54 AM
Hi @Eva0 ,
You were close . I think the first astrik "*" was not needed because the input json is not contained in an array brackets. Then to include the email in each data element it has to be added at the date & type level but to reference the value you need to go to 2 levels up using the @ character as in @(2,mail) where the email is located in relative to date & type.
[
{
"operation": "shift",
"spec": {
//level 2 where email originally is
"dates": {
// level 1
"*": {
// start count here at level 0
"@(2,email)": "[&1].email",
"date": "[&1].date",
"type": "[&1].type"
}
}
}
}
]
If you find this helpful please accept solution.
Thanks