Parse Array with respect to colon in jolt transforms processor in Apache Nifi

Viewed 50

How to parse or split an array with respect to colon(s) in jolt transformation processor in Apache NiFi.

input:

{
  "metricname": [
    "CPU1min",
    "MemoryFree",
    "MemoryUsed"
  ],
  "dataSourceName": "Standard CPU Utilization Network Cisco",
  "paramname": {
    "Standard CPU Utilization Network Cisco-3745 chassis Index0": {
      "values": [
        [
          "No Data",
          "No Data",
          "No Data",
          "No Data",
          "No Data"
        ],
        [
          "No Data",
          "No Data",
          "No Data",
          "No Data",
          "No Data"
        ],
        [
          "No Data",
          "No Data",
          "No Data",
          "No Data",
          "No Data"
        ]
      ]
    }
  }
}

expected output:

[
  "metricname",
  [
    "CPU1min",
    "MemoryFree",
    "MemoryUsed"
  ],
  "dataSourceName",
  "Standard CPU Utilization Network Cisco",
  "paramname",
  "Standard CPU Utilization Network Cisco-3745 chassis Index0",
  "values",
  [
    "No Data",
    "No Data",
    "No Data",
    "No Data",
    "No Data"
  ],
  [
    "No Data",
    "No Data",
    "No Data",
    "No Data",
    "No Data"
  ],
  [
    "No Data",
    "No Data",
    "No Data",
    "No Data",
    "No Data"
  ]
]

please help me out.

Thanks

1 Answers

You can use "$" and "@" wildcards for generating key and value pairs, respectively within two successive shift transformations in order to get a unique array as result by melting down resembling stairs in shape such as

[
  {
    "operation": "shift",
    "spec": {
      "*": {
        "$": "",
        "@": ""
      },
      "para*": {
        "$": "",
        "*": {
          "$": "",
          "*": {
            "$": "",
            "*": {
              "@": ""
            }
          }
        }
      }
    }
  }
]

the demo on the site http://jolt-demo.appspot.com/ is: enter image description here

Related