Created on 09-06-2022 01:33 PM - edited 09-06-2022 02:46 PM
I am trying to understand simple jolt transformations
My original json
{
"name" : "john",
"Address2" : "123 Street 1",
"Address1" : "Apt 101",
"custId" : "ZY-1234",
"zip" : "67834"
}
I would like to change the sequence of columns and get comma separated values with default tags added to it, like below
The last column value should be defaulted to current datetime
{
"Rows" : [
{ "values" : [ "ZY-1234" , "john" , "123 Street 1","Apt 101","67834","2022-09-01 10:10:09" ] }
],
"operationType" : "Insert",
"Source" : "Dev"
}
here is the Spec I got to
[
{
"operation": "default",
"spec": {
"ChangedBy": "NIFI",
"ChangedOn": "${now()}"
}
},
{
"operation": "shift",
"spec": {
"*": {
"@": "Rows[#1].Value"
}
}
},
{
"operation": "default",
"spec": {
"*": {
"*": "&"
},
"operationType": "Insert",
"Source": "Dev"
}
}
]
The Result of this
{
"Rows" : [ {
"Values" : [ "john", "123 Street 1", "Apt 101", "ZY-1234", "67834", "NIFI", "${now()}" ]
} ],
"operationType" : "Insert",
"Source" : "Dev"
}
Issues :
1. How to change the column sequence in Values array
2. How to get current datetime
Created 09-06-2022 02:17 PM
@VenkatG ,
What are you trying to use this resulting JSON for? That seems a bit odd of a format to me.
Nevertheless, here's a JOLT to achieve that (or close):
[
{
"operation": "default",
"spec": {
"__timestamp": "${now()}"
}
},
{
"operation": "shift",
"spec": {
"custId": "Rows[0].values[0]",
"name": "Rows[0].values[1]",
"Address2": "Rows[0].values[2]",
"Address1": "Rows[0].values[3]",
"zip": "Rows[0].values[4]",
"__timestamp": "Rows[0].values[5]"
}
},
{
"operation": "default",
"spec": {
"operationType": "Insert",
"Source": "Dev"
}
}
]
Cheers,
André
Created 09-09-2022 04:43 PM
@VenkatG Has the reply helped resolve your issue? If so, please mark the appropriate reply as the solution, as it will make it easier for others to find the answer in the future. Thanks
Regards,
Diana Torres,