There are some slight changes with NiFi’s Jolt compared to the test site — NiFi 
is automatically applying a chain operation but you can change that in the 
processor configuration. I’d also recommend using the Custom View on the JTJ 
processor to have a better interface for applying your transform.

The code you’re using to iterate over the flowfile attributes should work, but 
you can optimize/Groovy-fy it. Why not just write to the log for debugging 
rather than to a remote file? Also, this will overwrite the same file every 
time a flowfile comes through this script.


Andy LoPresto
[email protected]
[email protected]
PGP Fingerprint: 70EC B3E5 98A6 5A3F D3C4  BACE 3C6E F65B 2F7D EF69

> On Sep 4, 2018, at 4:05 PM, l vic <[email protected]> wrote:
> 
> Thank you, works on the Jolt demo site. With real Nifi it doesn't. I am 
> trying to print those values in ExecuteScript with Groovy script iterating 
> flowfile attributets:
> import org.apache.commons.io.IOUtils
> import java.nio.charset.StandardCharsets
> import org.apache.nifi.processor.io.StreamCallback
> 
> def flowFile = session.get()
> def file1 = new File('/home/me/groovy/attributes.txt')
> file1.write '##############################################\n'
>     flowFile.getAttributes().each { key,value ->
>       file1.append(key+' :')
>       file1.append(value + '\n')
>     }
> session.transfer(flowFile,REL_SUCCESS)
> None of them show up. Is there some way to read them from ExecuteScript?
> 
> On Tue, Sep 4, 2018 at 12:56 PM Matt Burgess <[email protected] 
> <mailto:[email protected]>> wrote:
> Add the following to the end of your shift spec:
> 
> "*": "&"
> 
> This (at the root) matches any key not already matched and puts it in
> the output at the same location.
> 
> Regards,
> Matt
> 
> On Tue, Sep 4, 2018 at 11:39 AM l vic <[email protected] 
> <mailto:[email protected]>> wrote:
> >
> > Hi,
> > I want to "flatten" the following object:
> > {
> >     "id": 0,
> >     "name": "Root",
> >      "mylist": [{
> >       "id": 10,
> >       "info": "2am-3am"
> >     },
> >     {
> >         "id": 11,
> >         "info": "3AM-4AM"
> >     },
> >     {
> >         "id": 12,
> > "info": "4am-5am"
> >     }]
> > }
> > I figured how to "flatten" array, but "root" values are gone in transformed 
> > output:
> > {
> >    "mylist-0-id":10,
> >    " mylist-0-info":"2am-3am",
> > ....
> > }
> > How can I retain "root" fields so that transformed output would like like 
> > one below?
> > {
> >      "id": 0,
> >     "name": "Root",
> >      "mylist-0-id":10,
> >    " mylist-0-info":"2am-3am",
> > ....
> > }
> >
> >

Attachment: signature.asc
Description: Message signed with OpenPGP using GPGMail

Reply via email to