Support Questions
Find answers, ask questions, and share your expertise
Announcements
Alert: Welcome to the Unified Cloudera Community. Former HCC members be sure to read and learn how to activate your account here.

Alter format of JSON date using NIFI groove exec script

Highlighted

Alter format of JSON date using NIFI groove exec script

New Contributor

I am trying to dynamically change the date format of my json file before I send it.

import groovy.json.*

def ff = session.get()
if(!ff) return
ff = session.write(ff, {rawIn, rawOut->
    //parse flowfile content to maps & arrays
    def json = new JsonSlurper().parse(rawIn, "UTF-8")
    //change json 
    json.revision.version =  (json.revision.version as Long) + 1
    //write to output changed content
    rawOut.withWriter("UTF-8"){ it.write( JsonOutput.toJson(json) )}
} as StreamCallback)
session.transfer(ff, REL_SUCCESS)

This is the closest I have been able to get by pulling together different tutorials. This is my JSON, this is just one value of data and date but there will be many:

{
  "test" : [ {
    "data" : "119050300",
    "date" : "00:00 2019-06-03"
  } ]
}

How can I use the above script to turn my date into a date time format like this:

{
  "test" : [ {
    "data" : "119050300",
    "date" : "2019-06-03'T'10:00"
  } ]
}
Don't have an account?
Coming from Hortonworks? Activate your account here