Support Questions

Find answers, ask questions, and share your expertise

How to rename array key names in NiFi?

avatar
New Contributor

Hello,

I need a little help, I want to rename all keys in the array "orderItems"

Input:

 

{
  "id": 105,
  "referrerId": 0,
  "typeId": 1,
  "orderItems": [
    {
      "id": 115,
      "typeId": 6,
      "itemVariationId": 0,
      "quantity": 1,
      "attributeValues": null,
      "vatField": 0,
      "amounts": [
        {
          "currency": "EUR",
          "priceGross": 5.99,
          "priceNet": 5.0336,
          "discount": 0
        }
      ]
    },
    {
      "id": 116,
      "typeId": 2,
      "itemVariationId": 1088,
      "quantity": 1,
      "attributeValues": "5",
      "vatField": 0,
      "amounts": [
        {
          "currency": "EUR",
          "priceGross": 29.9,
          "priceNet": 25.1261,
          "discount": 0
        }
      ]
    }
  ],
  "addressRelations": [
    {
      "id": 10,
      "orderId": 105,
      "typeId": 1,
      "addressId": 7
    },
    {
      "id": 11,
      "orderId": 105,
      "typeId": 2,
      "addressId": 7
    }
  ]
}

 

Excepted Output:

 

{
  "id": 105,
  "referrerId": 0,
  "plentyId": 61757,
  "typeId": 1,
  "orderItems": [
    {
      "text01": 115,
      "text02": 6,
      "text03": 0,
      "text04": 1,
      "text05": null,
      "text06": 0,
      "amounts": [
        {
          "currency": "EUR",
          "priceGross": 5.99,
          "priceNet": 5.0336,
          "discount": 0
        }
      ]
    },
    {
      "text01": 116,
      "text02": 2,
      "text03": 1088,
      "text04": 1,
      "text05": "5",
      "text06": 0,
      "amounts": [
        {
          "currency": "EUR",
          "priceGross": 29.9,
          "priceNet": 25.1261,
          "discount": 0
        }
      ]
    }
  ],
  "addressRelations": [
    {
      "id": 10,
      "orderId": 105,
      "typeId": 1,
      "addressId": 7
    },
    {
      "id": 11,
      "orderId": 105,
      "typeId": 2,
      "addressId": 7
    }
  ]
}

 

I have tried some JOLT-Specs, but nothing worked. 

Hope, somebody can help me 🙂

Thanks!

1 REPLY 1

avatar
Expert Contributor

Hello,

 

can you try it with: 

 

[
  {
    "operation": "shift",
    "spec": {
      "orderItems": {
        "*": {
          "id": "orderItems[&1].text01",
          "typeId": "orderItems[&1].text02",
          "itemVariationId": "orderItems[&1].text03",
          "quantity": "orderItems[&1].text04",
          "attributeValues": "orderItems[&1].text05",
          "vatField": "orderItems[&1].text06",
          "amounts": "orderItems[&1].amounts"
        }
      },
      "*": "&"
    }
  }
]

 Let me know if there needs something to change.

 

Greetings