Search code examples
jsonapache-nifijolt

How do I assign a null value to a key which already has a existing value. I need to assign null value to a key because it satisifed a condition


based on a condition which says that if customer name from both tables match then few columns from one of the table should be assigned as null.I have all the input which which matches the condition, but I am not able to set the required columns as null

Input:

[
  {
    "IN_num": "3",
    "In_Details": "404 error",
    "customer_name": "vivo",
    "customer_location": "hyd",
    "customer_ID": "1003"
  },
  {
    "IN_num": "2",
    "In_Details": "404 error",
    "customer_name": "MI",
    "customer_location": "hyd",
    "customer_ID": "1002"
  },
  {
    "IN_num": "1",
    "In_Details": "notworking",
    "customer_name": "Nokia",
    "customer_location": "Hyd",
    "customer_ID": "1001"
  }
]

I have tried creating a fake null value and assign it to the required key but still I am getting the already existing value that the key already has.

My spec:

[
  {
    "operation": "modify-overwrite-beta",
    "spec": {
      "*": {
        "N1": [
          "=isNull(@(1,customer_ID))",
          "NuLl"
        ],
        "N2": [
          "=isNull(@(1,customer_location))",
          "NotNuLl"
        ],
        "Condition": "=concat(@(1,N1),'_',@(1,N2))",
        "test": null
      }
    }
  },
  {
    "operation": "shift",
    "spec": {
      "*": {
        "IN_num": "[&1].IN_num",
        "In_Details": "[&1].In_Details",
        "customer_name": "[&1].customer_name",
        "test": "[&1].test",
        "customer_location": "[&1].customer_location",
        "Condition": {
          "NuLl_NotNuLl": {
            "@2,test": "customer_location"
          }
        }
      }
    }
  }
]

here customer location has an existing value but I want it to be printed as "".

output that im getting:

[
  {
    "IN_num": "3",
    "In_Details": "404 error",
    "customer_name": "vivo",
    "test": null,
    "customer_location": "hyd"
  },
  {
    "IN_num": "2",
    "In_Details": "404 error",
    "customer_name": "MI",
    "test": null,
    "customer_location": "hyd"
  },
  {
    "IN_num": "1",
    "In_Details": "notworking",
    "customer_name": "Nokia",
    "test": null,
    "customer_location": "Hyd"
  }
]

for the key ""customer_location" I want the value to be "" or null.

how to proceed with this?


Solution

  • I'm not sure about your expected result. If you are looking for a condition like if else statement then the below spec can help you.

    [
    {
    "operation": "modify-overwrite-beta",
    "spec": {
      "*": {
        "N1": ["=isNull(@(1,customer_ID))", "NuLl"],
        "N2": ["=isNull(@(1,customer_location))", "NotNuLl"],
        "Condition": "=concat(@(1,N1),'_',@(1,N2))",
        "test": null
      }
    }
    }, {
    "operation": "shift",
    "spec": {
      "*": {
        "IN_num": "[&1].IN_num",
        "In_Details": "[&1].In_Details",
        "customer_name": "[&1].customer_name",
        "test": "[&1].test",
        "Condition": {
          "NuLl_NotNuLl": { //if
            "@2,test": "[&3].customer_location"
          },
          "*": { //else
            "@2,customer_location": "[&3].customer_location"
          }
        }
      }
    }
    }]
    

    enter image description here

    Let us know If you are looking for something different.