Created on 09-29-2025 08:08 AM - edited 09-29-2025 08:42 AM
i have a JSON payload which contains latest and old orders. The data should be compared and output New, update, deleted. How can do it do that in NIFI?.
Created 09-29-2025 01:08 PM
Hi @steven-matison @MattWho @mburgess Do you have any insights here? Thanks!
Regards,
Diana Torres,Created 09-30-2025 05:23 AM
You can use ExecuteGroovyScript with the following script:
def ff = session.get()
if (!ff) return
def obj = new groovy.json.JsonSlurper().parse(ff.read())
def outObj = []
// Find updated records
def old_ids = obj.old_orders.collect {it.order_id}
def latest_ids = obj.latest_orders.collect {it.order_id}
old_ids.intersect(latest_ids).each {order_id ->
def update_order = obj.latest_orders.find {it.order_id == order_id}
update_order.Action = 'UPDATE'
outObj += update_order
}
// Find deleted records
(old_ids - latest_ids).each {order_id ->
def delete_order = obj.old_orders.find {it.order_id == order_id}
delete_order.Action = 'DELETE'
outObj += delete_order
}
// Find new records
(latest_ids - old_ids).each {order_id ->
def new_order = obj.latest_orders.find {it.order_id == order_id}
new_order.Action = 'NEW'
outObj += new_order
}
ff.write('UTF-8', groovy.json.JsonOutput.toJson(outObj))
REL_SUCCESS << ff
Created 10-06-2025 06:36 AM
Hi @Althotta
Have you been able to resolve your issue? If so, please mark the appropriate reply as the solution, as it will make it easier for others to find the answer in the future.