Archives of Support Questions (Read Only)

This is an archived board for historical reference. Information and links may no longer be available or relevant
Announcements
This board is archived and read-only for historical reference. To ask a new question, please post a new topic on the appropriate active board.

How to use processor ReplaceWithMapping in nifi?

avatar
New Member

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 Member

@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