Support Questions

Find answers, ask questions, and share your expertise
Announcements
Celebrating as our community reaches 100,000 members! Thank you!

Not Getting Jolt output as expected in NiFi

avatar
Explorer

I have below input:

 

[
{
"seq_no": 18,
"Id": 174052,
"Date": "2021-12-26T00:00:00Z"
},
{
"seq_no": 19,
"Id": 174052,
"Date": "2021-12-26T00:00:00Z"
}
]

 

Jolt Spec:

 

[

{
"operation": "modify-overwrite-beta",
"spec": {
"*": {
"seq_no": "=toString",
"Date": "=substring(@(1,REVISION_IND),0,10)"
}
}
},
{
"operation": "shift",
"spec": {
"*": {
"seq_no": "[&1].seq_no",
"Id": "[&1].Id",
"Date": "[&1].Date"
}
}
},
{
"operation": "shift",
"spec": {
"*": "data"
}
},
{
"operation": "default",
"spec": {
"header": {
"submit": "true",
"comments": "3"
}
}
}
]

 

Output:

{
"data" : [ {
"seq_no" : "18",
"Id" : 174052,
"Date" : "2021-12-26T00:00:00Z"
}, {
"seq_no" : "19",
"Id" : 174052,
"Date" : "2021-12-26T00:00:00Z"
} ],
"header" : {
"submit" : "true",
"comments" : "3"
}
}

 

Desired Output:

 

{
"header" : {
"submit" : "true",
"comments" : "3"
},
"data" : [ {
"seq_no" : "18",
"Id" : 174052,
"Date" : "2021-12-26T00:00:00Z"
}, {
"seq_no" : "19",
"Id" : 174052,
"Date" : "2021-12-26T00:00:00Z"
} ]
}

 

Can you please help how I will get the header part and then the data. I used sort but it's not helping me. Appreciate your help. Thank you.

2 REPLIES 2

avatar
Expert Contributor

Hello,

 

you can add following object as last step to your JOLT Spec:

{
    "operation": "shift",
    "spec": {
      "header": "header",
      "data": "data"
    }
}

 

Greetings

avatar
Explorer

Hi @Faerballert , 

Thank you so much. I tried it earlier the same but not sure why it were not working.

some of my fields contains null values. But instead of null I want the empty string in the same jolt. Can we do that? is there any option to do the same.