Support Questions

Find answers, ask questions, and share your expertise

add plus minutes to a date time value with the jolt transform json processor

Explorer

 

 

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
}

 

 

 

2 ACCEPTED SOLUTIONS

Super Collaborator

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.

 

View solution in original post

Explorer

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

View solution in original post

2 REPLIES 2

Super Collaborator

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.

 

Explorer

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

Take a Tour of the Community
Don't have an account?
Your experience may be limited. Sign in to explore more.