nifi-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From idioma <>
Subject Re: Help with ReplaceTextWithMapping processor: multi-column mappings
Date Wed, 01 Jun 2016 12:31:00 GMT
Hi Andy, apologies for the delay in replying. I have come back to the task
and tried to write a simple Groovy script in order to make the substitutions
coming from the mapping files. In order to have something working, I have
modified the mapping files, so that each of the incoming Json values
initially translate into "some text". I am harcoding the substitution in the
below script:

import groovy.json.JsonBuilder
import groovy.json.JsonSlurper
import java.nio.charset.StandardCharsets

def flowFile = session.get();
if (flowFile == null) {

flowFile = session.write(flowFile,
        { inputStream, outputStream ->

            def content = """
  "field2": "some text",
  "field3": "some text"


            def slurped = new JsonSlurper().parseText(content)
            def builder = new JsonBuilder(slurped)
            builder.content.field2 = "A"
            builder.content.field3 = "A*"
        } as StreamCallback)
session.transfer(flowFile, ExecuteScript.REL_SUCCESS)

The substitutions work fine, but obviously the approach is very much
hardcoded. First off, how do I map the attribute 'content' to my flowfile?
The preceding processor is UpdateAttribute where I simply map the incoming
flowfile to the filename = myResultingJson.json. Secondly, is it possible to
load the mapping file with the replacements via Groovy in the script and
make Groovy to work out the mapping in a more generic way?

Thank you so much for your help,


View this message in context:
Sent from the Apache NiFi Developer List mailing list archive at

View raw message