Search code examples
jsonapache-nifijolt

NiFi Jolt Specification for array input


I have the following input in Nifi Jolt Specification processor:

[
  {
    "values": [
      {
        "id": "paramA",
        "value": 1
      }
    ]
  },
  {
    "values": [
      {
        "id": "paramB",
        "value": 3
      }
    ]
  }
]

Expected output:

[
  {
    "id": "paramA",
    "value": 1
  },
  {
    "id": "paramB",
    "value": 2
  }
]

Can you explain how I have to do?

thanks in advance


Solution

  • You want to reach the objects of the values array which are nested within seperate object signs ({}). A "*" notation is needed in order to cross them over per each individual values array, and then use another "*" notation for indexes of those arrays while choosing "" as the counterpart values in order to grab nothing but the sub-objects such as

    [
      {
        "operation": "shift",
        "spec": {
          "*": {
            "values": {
              "*": ""
            }
          }
        }
      }
    ]
    

    enter image description here