Support Questions

Find answers, ask questions, and share your expertise
Announcements
Celebrating as our community reaches 100,000 members! Thank you!

How to use processor ReplaceWithMapping in nifi?

avatar
New Contributor

I have splited data json like this:

{"id":"TSO31101","year":"1992","name":"SDN","npsn":"20211628"}

I want to replace "SDN" and "TSO31101" contents using processor ReplaceTextWithMapping

my mapping file content like this:

SDN<tab>SD

TSO31101<tab>AAAA

how it is work?

1 ACCEPTED SOLUTION

avatar

I not sure ReplaceWithMapping is powerful enough ...

I would anyhow prefer a solution like this (look at the edited answer at the bottom):

http://stackoverflow.com/questions/37577453/apache-nifi-executescript-groovy-script-to-replace-json-...

You have more control which values of which keys you actually replace and you can replace multiple values in one record

View solution in original post

3 REPLIES 3

avatar

I not sure ReplaceWithMapping is powerful enough ...

I would anyhow prefer a solution like this (look at the edited answer at the bottom):

http://stackoverflow.com/questions/37577453/apache-nifi-executescript-groovy-script-to-replace-json-...

You have more control which values of which keys you actually replace and you can replace multiple values in one record

avatar
New Contributor

@Bernhard Walte

The result from ExecuteScript Groovy is:

{bentuk=SD, field2=cd, field3=A2}

Can I get the output with the json format?

thanks for your solutions, im looking forward for your reply 🙂

avatar

Replace

outputStream.write(inJson.toString().getBytes(StandardCharsets.UTF_8))

by

def outJson = new JsonBuilder(inJson)
outputStream.write(outJson.toString().getBytes(StandardCharsets.UTF_8))

The referenced sample in StackOverflow already imports jsonBuilder