Search code examples
jsonapache-nifijolt

Extract particular fields from json array Nifi


I have the following input json, which has an array of json:

{
  "ArrayList": [
    {
      "a": "value1",
      "b": "value2",
      "c": "value3"
    },
    {
      "a": "value4",
      "b": "value5",
      "c": "value6"
    },
    {
      "a": "value7",
      "b": "value8",
      "c": "value9"
    }
  ]
}

And the desired output is :

{
  "ArrayList": [
    {
      "a": "value1",
      "b": "value2"
    },
    {
      "a": "value4",
      "b": "value5"
    },
    {
      "a": "value7",
      "b": "value8"
    }
  ]
}

What will be the Jolt transform spec expression for this?


Solution

  • Seems you want to remove the attribute c of objects of the ArrayList array, then a remove transformation might be used such as

    [
      {
        "operation": "remove",
        "spec": {
          "ArrayList": {
            "*": {
              "c": ""
            }
          }
        }
      }
    ]