<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>question Re: Dynamic property naming in NiFi in Support Questions</title>
    <link>https://community.cloudera.com/t5/Support-Questions/Dynamic-property-naming-in-NiFi/m-p/216693#M178602</link>
    <description>&lt;P&gt;Maybe there's another way to ask this; I shouldn't pre-suppose dynamic naming is necessary.&lt;/P&gt;&lt;P&gt;Say I have this JSON document:&lt;/P&gt;&lt;P&gt;{
"boxes": [{
"box": {
"oranges": 2,
"apples": 5
}
},
{
"box": {
"oranges": 2,
"bananas": 7
}
}
]
}&lt;/P&gt;&lt;P&gt;I need to then do some work to create something like this:&lt;/P&gt;&lt;P&gt;{
"boxes": [{
"box": 1,
"fruits": 2,
"count": 7
},
{
"box": 2,
"fruits": 2,
"count": 9
}
]
}&lt;/P&gt;&lt;P&gt;My thinking was first split by box to get a "box" attribute and 2 flowfiles. Then split by contents of each box to create 4 flowfiles each with a "fruit" attribute. But how do I merge back to construct pieces of the final output? The attribute names would be the same with different values. I need for the attribute names to be different (like box.1, box.2, fruit.1, fruit.2) which would be easy using fragment indexes, but I can't seem to name properties dynamically like that.  Is there an alternative?&lt;/P&gt;&lt;P&gt;Does that make any sense?&lt;/P&gt;&lt;P&gt;Thanks,&lt;/P&gt;&lt;P&gt;JP&lt;/P&gt;</description>
    <pubDate>Sat, 10 Feb 2018 04:42:06 GMT</pubDate>
    <dc:creator>james_poriz</dc:creator>
    <dc:date>2018-02-10T04:42:06Z</dc:date>
    <item>
      <title>Dynamic property naming in NiFi</title>
      <link>https://community.cloudera.com/t5/Support-Questions/Dynamic-property-naming-in-NiFi/m-p/216692#M178601</link>
      <description>&lt;P&gt;Hi there,&lt;/P&gt;&lt;P&gt;I'm in a situation where I need to be able to set the name of a property using Expression Language. Is there any way to do that?&lt;/P&gt;&lt;P&gt;I try to create an attribute using an UpdateAttribute processor and put in ${property1} as the property name. Now, property1 is in reference to an existing attribute containing the value "property2". What I'd hope is that the flowfile has a new property added named "property2" but what I end up with is a new property literally named "${property1}".&lt;/P&gt;&lt;P&gt;Is this even possible?&lt;/P&gt;&lt;P&gt;Thanks,&lt;/P&gt;&lt;P&gt;JP&lt;/P&gt;</description>
      <pubDate>Sat, 10 Feb 2018 04:04:30 GMT</pubDate>
      <guid>https://community.cloudera.com/t5/Support-Questions/Dynamic-property-naming-in-NiFi/m-p/216692#M178601</guid>
      <dc:creator>james_poriz</dc:creator>
      <dc:date>2018-02-10T04:04:30Z</dc:date>
    </item>
    <item>
      <title>Re: Dynamic property naming in NiFi</title>
      <link>https://community.cloudera.com/t5/Support-Questions/Dynamic-property-naming-in-NiFi/m-p/216693#M178602</link>
      <description>&lt;P&gt;Maybe there's another way to ask this; I shouldn't pre-suppose dynamic naming is necessary.&lt;/P&gt;&lt;P&gt;Say I have this JSON document:&lt;/P&gt;&lt;P&gt;{
"boxes": [{
"box": {
"oranges": 2,
"apples": 5
}
},
{
"box": {
"oranges": 2,
"bananas": 7
}
}
]
}&lt;/P&gt;&lt;P&gt;I need to then do some work to create something like this:&lt;/P&gt;&lt;P&gt;{
"boxes": [{
"box": 1,
"fruits": 2,
"count": 7
},
{
"box": 2,
"fruits": 2,
"count": 9
}
]
}&lt;/P&gt;&lt;P&gt;My thinking was first split by box to get a "box" attribute and 2 flowfiles. Then split by contents of each box to create 4 flowfiles each with a "fruit" attribute. But how do I merge back to construct pieces of the final output? The attribute names would be the same with different values. I need for the attribute names to be different (like box.1, box.2, fruit.1, fruit.2) which would be easy using fragment indexes, but I can't seem to name properties dynamically like that.  Is there an alternative?&lt;/P&gt;&lt;P&gt;Does that make any sense?&lt;/P&gt;&lt;P&gt;Thanks,&lt;/P&gt;&lt;P&gt;JP&lt;/P&gt;</description>
      <pubDate>Sat, 10 Feb 2018 04:42:06 GMT</pubDate>
      <guid>https://community.cloudera.com/t5/Support-Questions/Dynamic-property-naming-in-NiFi/m-p/216693#M178602</guid>
      <dc:creator>james_poriz</dc:creator>
      <dc:date>2018-02-10T04:42:06Z</dc:date>
    </item>
    <item>
      <title>Re: Dynamic property naming in NiFi</title>
      <link>https://community.cloudera.com/t5/Support-Questions/Dynamic-property-naming-in-NiFi/m-p/216694#M178603</link>
      <description>&lt;P&gt;Alternately, is there a way to get the size of a JSON array using EvaluateJSONPath?&lt;/P&gt;</description>
      <pubDate>Sat, 10 Feb 2018 05:35:21 GMT</pubDate>
      <guid>https://community.cloudera.com/t5/Support-Questions/Dynamic-property-naming-in-NiFi/m-p/216694#M178603</guid>
      <dc:creator>james_poriz</dc:creator>
      <dc:date>2018-02-10T05:35:21Z</dc:date>
    </item>
    <item>
      <title>Re: Dynamic property naming in NiFi</title>
      <link>https://community.cloudera.com/t5/Support-Questions/Dynamic-property-naming-in-NiFi/m-p/216695#M178604</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;Take a look at the JoltTransformJSON processor, it is capable to do the exact transformation you need.&lt;/P&gt;&lt;P&gt;More info about Jolt:&lt;/P&gt;&lt;P&gt;&lt;A href="https://github.com/bazaarvoice/jolt"&gt;https://github.com/bazaarvoice/jolt&lt;/A&gt;&lt;/P&gt;&lt;P&gt;&lt;A href="http://jolt-demo.appspot.com/"&gt;http://jolt-demo.appspot.com/&lt;/A&gt;&lt;/P&gt;&lt;P&gt;Cheers.&lt;/P&gt;</description>
      <pubDate>Thu, 22 Mar 2018 00:44:49 GMT</pubDate>
      <guid>https://community.cloudera.com/t5/Support-Questions/Dynamic-property-naming-in-NiFi/m-p/216695#M178604</guid>
      <dc:creator>quakerlive</dc:creator>
      <dc:date>2018-03-22T00:44:49Z</dc:date>
    </item>
    <item>
      <title>Re: Dynamic property naming in NiFi</title>
      <link>https://community.cloudera.com/t5/Support-Questions/Dynamic-property-naming-in-NiFi/m-p/216696#M178605</link>
      <description>&lt;A rel="user" href="https://community.cloudera.com/users/13151/jamesporiz.html" nodeid="13151" target="_blank"&gt;@JP&lt;/A&gt;&lt;P&gt;One way of doing it is using &lt;STRONG&gt;ExecuteScript&lt;/STRONG&gt; Processor. Follows a sample solution.&lt;/P&gt;&lt;P&gt;I generated a flow file using &lt;STRONG&gt;GenerateFlowFile&lt;/STRONG&gt; Processor which has an attribute named "&lt;EM&gt;Property1&lt;/EM&gt;" with the value set to "&lt;EM&gt;Property2&lt;/EM&gt;".&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="64755-screen-shot-2018-03-22-at-121100-am.png" style="width: 1524px;"&gt;&lt;img src="https://community.cloudera.com/t5/image/serverpage/image-id/16222i726B84A96C970850/image-size/medium?v=v2&amp;amp;px=400" role="button" title="64755-screen-shot-2018-03-22-at-121100-am.png" alt="64755-screen-shot-2018-03-22-at-121100-am.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;Now, this goes to an &lt;STRONG&gt;ExecuteScript&lt;/STRONG&gt; Processor where I am using a Groovy script to create a new property "&lt;EM&gt;on the fly&lt;/EM&gt;"!&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="64756-screen-shot-2018-03-22-at-121342-am.png" style="width: 1544px;"&gt;&lt;img src="https://community.cloudera.com/t5/image/serverpage/image-id/16223iBF95355C805BEBD1/image-size/medium?v=v2&amp;amp;px=400" role="button" title="64756-screen-shot-2018-03-22-at-121342-am.png" alt="64756-screen-shot-2018-03-22-at-121342-am.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;Follows the groovy script which is creating the property on the fly.&lt;/P&gt;&lt;PRE&gt;flowFile = session.get()
if(!flowFile) return
myAttr = flowFile.getAttribute('property1')
flowFile = session.putAttribute(flowFile, myAttr, 'myValue')
session.transfer(flowFile, REL_SUCCESS)&lt;/PRE&gt;&lt;P&gt;The flow file coming out of this processor looks something like this.&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="64757-screen-shot-2018-03-22-at-121458-am.png" style="width: 944px;"&gt;&lt;img src="https://community.cloudera.com/t5/image/serverpage/image-id/16224iB40048856B48BFCB/image-size/medium?v=v2&amp;amp;px=400" role="button" title="64757-screen-shot-2018-03-22-at-121458-am.png" alt="64757-screen-shot-2018-03-22-at-121458-am.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;Hope that helps!&lt;/P&gt;</description>
      <pubDate>Sun, 18 Aug 2019 03:07:40 GMT</pubDate>
      <guid>https://community.cloudera.com/t5/Support-Questions/Dynamic-property-naming-in-NiFi/m-p/216696#M178605</guid>
      <dc:creator>RahulSoni</dc:creator>
      <dc:date>2019-08-18T03:07:40Z</dc:date>
    </item>
    <item>
      <title>Re: Dynamic property naming in NiFi</title>
      <link>https://community.cloudera.com/t5/Support-Questions/Dynamic-property-naming-in-NiFi/m-p/216697#M178606</link>
      <description>&lt;P&gt;As per Taras' answer; a JOLT transform ended up being exactly what we needed.&lt;/P&gt;</description>
      <pubDate>Thu, 22 Mar 2018 20:22:36 GMT</pubDate>
      <guid>https://community.cloudera.com/t5/Support-Questions/Dynamic-property-naming-in-NiFi/m-p/216697#M178606</guid>
      <dc:creator>james_poriz</dc:creator>
      <dc:date>2018-03-22T20:22:36Z</dc:date>
    </item>
  </channel>
</rss>

