Search code examples
jsonsplitapache-nifijolt

JSON attribute value split by space and put them into new attributes using Jolt transform Apache nifi


I have json object as following,

{
    "sensorId":2,
    "dataValue":26.7, 
    "dateTime":"2020:12:29 14:20:31"
}

I want to convert it to the following,

{
    "sensorId":2,
    "dataValue":26.7, 
    "date":"2020:12:29",
    "time":"14:20:31"
}

Using Apache nifi Jolt transform


Solution

  • you can split with space ("* *") and assign splitted parts.

    [
      {
        "operation": "shift",
        "spec": {
          "sensorId": "sensorId",
          "dataValue": "dataValue",
          "dateTime": {
            "* *": {
              "$(0,1)": "date",
              "$(0,2)": "time"
            }
          }
        }
      }
    ]