Search code examples
jsonapache-nifijolt

Getting array length in json, Nifi


I have the following input:

{
  "abc": [1,2,3,4,5],
  "ghf": [2,4,6,8]
}

In the desired output I wanted to have the array length of these fields.

{
   "abc" : 5,
   "ghf" : 4
} 

Which processors should I be using and how? Thanks in advance.


Solution

  • You can use modify-overwrite-beta transformation along with a list function called size within a JoltTransformJSON processor such as

    [
      {
        "operation": "modify-overwrite-beta",
        "spec": {
          "*": "=size(@(1,&))"
        }
      }
    ]