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) {
    return;
}

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*"
           
outputStream.write(builder.toPrettyString().getBytes(StandardCharsets.UTF_8))
        } 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,

Ilaria



--
View this message in context: 
http://apache-nifi-developer-list.39713.n7.nabble.com/Help-with-ReplaceTextWithMapping-processor-multi-column-mappings-tp10280p10864.html
Sent from the Apache NiFi Developer List mailing list archive at Nabble.com.

Reply via email to