jsonapache-nifijolt

Jolt to change the key/values into code/values dynamically


I have following input JSON and want to convert these keys/values into codes/values, and need to convert the ts(timestamp) into CET time. These x1,x2,.... keys are dynamic. They can be like y1, y2...., etc and no of keys also dynamic.

Input JSON :

[
  {
    "x1": 29.684,
    "tz_offset": 3600,
    "x2": 29.957,
    "x3": -0.001,
    "x4": 0.041,
    "ts": 1727870442,
    "machine_name": "SL Station"
  }
]

Expected Output JSON :

{
  "Date": "2024-10-02 12:00:42",
  "data": [
    {
      "code": "x1",
      "value": 29.684
    },
    {
      "code": "x2",
      "value": 29.957
    },
    {
      "code": "x3",
      "value": -0.001
    },
    {
      "code": "x4",
      "value": 0.041
    }
  ],
  "machinename": "SL Station"
}

Could you please help in this. Thank you


Solution

  • You can use the processors in this order :

    whole picture would be like this :

    enter image description here