1
votes

Probably a simple beginners question:

Using NIFI, I want to split an array (represented flowfile-content) in the form of

["x1","x2", ..]

and format it to a JSON object of the form

{"key1":"x1", "key2":"x2", ..}

(also as flowfile-content)

What processor is the most efficent to be used, how would the expression script look like ?

Thanks in advance, Marc

1

1 Answers

0
votes

Applying Jolt transformations through use of a JoltTransformJSON processor might be a good choice. In which, you can add such a specification below by clicking on the ADVANCED button that's stated in the SETTINGS tab of Configure Processor dialog box :

[
  //Determine respective lists to be used to calculate their sizes within the next step 
  //in order to get ordinals for the key values
  {
    "operation": "shift",
    "spec": {
      "*": {
        "*": "&(0,0).[#2]"
      }
    }
  },
  {
    "operation": "modify-overwrite-beta",
    "spec": {
      "*": "=size(@(1,&))"
    }
  },
  //exchange key and values
  {
    "operation": "shift",
    "spec": {
      "*": {
        "$": "@(0)"
      }
    }
  },
  //add the desired word such as "key"
  {
    "operation": "shift",
    "spec": {
      "*": "key&(0,0)"
    }
  }
]