Sathyaraj
Sathyaraj

Reputation: 189

Need help in update JSON attributes from different flow file in Apache NiFi

I want to update an attribute in a JSON file with the value i get from other processor. Below is my Original JSON file.

{
 "applicant": {
        "applicant-id": null
        "full-name": "Tyrion Lannister",
        "mobile-number" : "8435739739",
        "email-id" : "[email protected]"
    },
    "product": {
        "product-category" : "Credit Card",
        "product-type" : "Super Value Card - Titanium"
    }
}

Below is my EvaluavateJsonPath Config where I extracted the applicant-id attribute.

enter image description here

Below is my GenerateFlowFile processor which generate an id value.

enter image description here

Now I need the update the applicant-id attribute with the value (899872120) in the Original JSON as below.

{
 "applicant": {
        "applicant-id": 899872120
        "full-name": "Tyrion Lannister",
        "mobile-number" : "8435739739",
        "email-id" : "[email protected]"
    },
    "product": {
        "product-category" : "Credit Card",
        "product-type" : "Super Value Card - Titanium"
    }
}

I tried to use MergeContent to merge the 2 flows and i can see the Applicant-Id attribute value in the flow file after the MergeContent processor. I tried using UpdateAttribue to update Applicant-Id but i'm not able get the update JSON record.

Below is my MergeContent Configuration.

enter image description here

Is there anything i'm missing?

Upvotes: 0

Views: 2341

Answers (1)

mattyb
mattyb

Reputation: 12103

As of NiFi 1.2.0, the JoltTransformJSON processor supports NiFi Expression Language, so if you have your id value in the attribute "Applicant-id", you can use it in a Default JOLT spec:

{
  "applicant": {
    "applicant-id": "${Applicant-id}"
  }
}

That should transform your input JSON to your desired output JSON.

Upvotes: 2

Related Questions