Created on 09-19-2022 06:53 AM - edited 09-19-2022 06:56 AM
Hi all,
I want to add 15 minutes to a date-time value using the transform json processor, but with my configuration I get the same value as before. I expect for the end field to have 15 minutes more than the start field. Does anyone have any idea?
[ {
"store_id" : 1001,
"date" : 20220918,
"start" : "2022-09-18 00:15:00",
"end" : "2022-09-18 00:15:00",
"out" : 0
}, {
"store_id" : 1001,
"date" : 20220918,
"start" : "2022-09-18 00:30:00",
"end" : "2022-09-18 00:30:00",
"out" : 0
}]
My jolt Specification
[
{
"operation": "modify-overwrite-beta",
"spec": {
"*":{
"end": "=${end:toDate('yyyy-MM-dd HH:mm:ss'):toNumber():plus(900000):format('yyyy-MM-dd HH:mm:ss')}"
}
}
}
]
The result is the same
[ {
"store_id" : 1001,
"date" : 20220918,
"start" : "2022-09-18 00:15:00",
"end" : "2022-09-18 00:15:00",
"out" : 0
}, {
"store_id" : 1001,
"date" : 20220918,
"start" : "2022-09-18 00:30:00",
"end" : "2022-09-18 00:30:00",
"out" : 0
}
Created on 09-19-2022 07:22 AM - edited 09-19-2022 07:23 AM
Hi,
I dont think the following formula is correct:
"end": "=${end:toDate('yyyy-MM-dd HH:mm:ss'):toNumber():plus(900000):format('yyyy-MM-dd HH:mm:ss')}"
You are trying to use Expression Language in the Jolt Expression and that is not going to work. Also the expression ${end...} assumes that you have an attribute called "end" which I don think its the case. I think what you need to do is the following (assuming you will need to split each json record into its own flowfile):
1- SplitJson
2- Use EvaluateJsonPath to extract the "end" date as an attribute
3- Use JoltTransformationJson where you utilize the attribute from above to do the addition as follows:
[
{
"operation": "modify-overwrite-beta",
"spec": {
"end": "${end_attribute:toDate('yyyy-MM-dd HH:mm:ss'):toNumber():plus(900000):format('yyyy-MM-dd HH:mm:ss')}"
}
}
]
Hope that helps, if it does please accept solution.
Created 09-19-2022 08:05 AM
Hi @SAMSAL,
thanks, i have try this out and it works. I thought you can directly edit the value of the JSON file. Now I have to merge all split JSON files into one again
Created on 09-19-2022 07:22 AM - edited 09-19-2022 07:23 AM
Hi,
I dont think the following formula is correct:
"end": "=${end:toDate('yyyy-MM-dd HH:mm:ss'):toNumber():plus(900000):format('yyyy-MM-dd HH:mm:ss')}"
You are trying to use Expression Language in the Jolt Expression and that is not going to work. Also the expression ${end...} assumes that you have an attribute called "end" which I don think its the case. I think what you need to do is the following (assuming you will need to split each json record into its own flowfile):
1- SplitJson
2- Use EvaluateJsonPath to extract the "end" date as an attribute
3- Use JoltTransformationJson where you utilize the attribute from above to do the addition as follows:
[
{
"operation": "modify-overwrite-beta",
"spec": {
"end": "${end_attribute:toDate('yyyy-MM-dd HH:mm:ss'):toNumber():plus(900000):format('yyyy-MM-dd HH:mm:ss')}"
}
}
]
Hope that helps, if it does please accept solution.
Created 09-19-2022 08:05 AM
Hi @SAMSAL,
thanks, i have try this out and it works. I thought you can directly edit the value of the JSON file. Now I have to merge all split JSON files into one again