skip to Main Content

For each array object, get the id and assign it as a key to the array object.
I am trying to use the JOLT processor in NIFI.
Any help would be much appreciated!

Input:

{
  "list": [
    {
      "catalog": {
        "id": "0981",
        "Desc": "Chess toy"
      },
      "quantity": 10,
      "price": 10.5
    },
    {
      "catalog": {
        "id": "01234",
        "Desc": "Water bottle"
      },
      "quantity": 5,
      "price": 5.4
    }
  ]
}

Expected output:

{
  "list": [
    {
      "0981": {
        "catalog": {
          "id": "0981",
          "Desc": "Chess toy"
        },
        "quantity": 10,
        "price": 10.5
      },
      "01234": {
        "catalog": {
          "id": "01234",
          "Desc": "Water bottle"
        },
        "quantity": 5,
        "price": 5.4
      }
    }
  ]
}

2

Answers


  1. You can use this shift transformation spec

    [
      {
        "operation": "shift",
        "spec": {
          "list": {
            "*": {
              "*": {
                "@": "&3[#4].@1,id.&",
                "@1,quantity": "&3[#4].@1,id.quantity",
                "@1,price": "&3[#4].@1,id.price"
              }
            }
          }
        }
      }
    ]
    

    where keys come from the identifier @1,id, &3 represents going tree three levels up to get the literal list and [#4] will bring them in array type manner.

    The following will do it all dynamically

    [
      {
        "operation": "shift",
        "spec": {
          "*": {
            "*": {
              "cat*": {
                "@": "&3[#4].@(1,id).&1"
              },
              "*": "&2[#3].@(1,catalog.id).&"
            }
          }
        }
      }
    ]
    
    Login or Signup to reply.
  2. You can use this spec:

    [
      {
        "operation": "shift",
        "spec": {
          "*": { // list
            "*": { // 0, 1
              "catalog": {
                "@": "&3.@(1,id).&1"
              },
              "*": "&2.@(1,catalog.id).&"
            }
          }
        }
      }
    ]
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search