<?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: NiFi - How to use JOLT to add json key:value  dynamically to the Flowfile content? in Archives of Support Questions (Read Only)</title>
    <link>https://community.cloudera.com/t5/Archives-of-Support-Questions/NiFi-How-to-use-JOLT-to-add-json-key-value-dynamically-to/m-p/222331#M72541</link>
    <description>&lt;P&gt;&lt;A rel="user" href="https://community.cloudera.com/users/18929/yaswanthmuppireddy.html" nodeid="18929"&gt;@Shu&lt;/A&gt; - Thanks a lot, it is really helpful.&lt;/P&gt;</description>
    <pubDate>Tue, 12 Dec 2017 17:14:46 GMT</pubDate>
    <dc:creator>hegdemahendra</dc:creator>
    <dc:date>2017-12-12T17:14:46Z</dc:date>
    <item>
      <title>NiFi - How to use JOLT to add json key:value  dynamically to the Flowfile content?</title>
      <link>https://community.cloudera.com/t5/Archives-of-Support-Questions/NiFi-How-to-use-JOLT-to-add-json-key-value-dynamically-to/m-p/222329#M72539</link>
      <description>&lt;P&gt;Input JSON content -&lt;/P&gt;&lt;P&gt;{
"exampledata": {
"name": "Test",
"age": null,
"ver": null,
"payloadType": "Text",
"payloadData": "adsadsdsdsdsdsdsdsdsds",
"sequenceNum": null,
"timeStamp": "2017-09-22T12:07:29.968Z"
}
}&lt;/P&gt;&lt;P&gt;Output expected - &lt;/P&gt;&lt;P&gt;{
    "exampledata": {
        "name": "Test",
        "age": null,         
        "ver": null,     
        "payloadType": "Text",
        "payloadData": "adsadsdsdsdsdsdsdsdsds",
        "sequenceNum": null,
        "timeStamp": "2017-09-22T12:07:29.968Z"
"company" : "CompanyName"
    }
}&lt;/P&gt;&lt;P&gt;company will be retrieved from Flowfile attribute and should be added to JSON Content. &lt;/P&gt;&lt;P&gt;Any help with JOLT Chain spec is much appreciated.&lt;/P&gt;&lt;P&gt;&lt;A href="https://community.hortonworks.com/questions/152046/nifi-how-to-use-jolt-to-add-json-keyvalue-dynamica.html#"&gt;@Matt Burgess&lt;/A&gt;&lt;/P&gt;</description>
      <pubDate>Mon, 11 Dec 2017 15:25:16 GMT</pubDate>
      <guid>https://community.cloudera.com/t5/Archives-of-Support-Questions/NiFi-How-to-use-JOLT-to-add-json-key-value-dynamically-to/m-p/222329#M72539</guid>
      <dc:creator>hegdemahendra</dc:creator>
      <dc:date>2017-12-11T15:25:16Z</dc:date>
    </item>
    <item>
      <title>Re: NiFi - How to use JOLT to add json key:value  dynamically to the Flowfile content?</title>
      <link>https://community.cloudera.com/t5/Archives-of-Support-Questions/NiFi-How-to-use-JOLT-to-add-json-key-value-dynamically-to/m-p/222330#M72540</link>
      <description>&lt;P&gt;&lt;A rel="user" href="https://community.cloudera.com/users/48523/hegdemahendra.html" nodeid="48523" target="_blank"&gt;@Mahendra Hegde&lt;/A&gt;,&lt;/P&gt;&lt;P&gt;According to jira &lt;A href="https://issues.apache.org/jira/browse/NIFI-3010" target="_blank" rel="nofollow noopener noreferrer"&gt;https://issues.apache.org/jira/browse/NIFI-3010&lt;/A&gt;&lt;/P&gt;&lt;P&gt;if you are using NiFi 1.2+ then we can use Attributes from the flowfile and add them to json.&lt;/P&gt;&lt;P&gt;I'm having Company attributes associated with the flowfile and value is also Company.&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;&lt;U&gt;Input:-&lt;/U&gt;&lt;/STRONG&gt;&lt;/P&gt;&lt;PRE&gt;{
"exampledata": {
"name": "Test",
"age": null,
"ver": null,
"payloadType": "Text",
"payloadData": "adsadsdsdsdsdsdsdsdsds",
"sequenceNum": null,
"timeStamp": "2017-09-22T12:07:29.968Z"
}
}&lt;/PRE&gt;&lt;P&gt;&lt;STRONG&gt;Jolt-spec:-&lt;/STRONG&gt;&lt;/P&gt;&lt;PRE&gt;[{
 "operation": "shift",
 "spec": {
  "*": "&amp;amp;"
 }
}, {
 "operation": "default",
 "spec": {
  "Company": "${Company}"
 }
}]
&lt;/PRE&gt;&lt;P&gt;&lt;STRONG&gt;Output:-&lt;/STRONG&gt;&lt;/P&gt;&lt;PRE&gt;{
"exampledata": {
"name": "Test",
"age": null,
"ver": null,
"payloadType": "Text",
"payloadData": "adsadsdsdsdsdsdsdsdsds",
"sequenceNum": null,
"timeStamp": "2017-09-22T12:07:29.968Z"
},
"Company": "Company"
}&lt;/PRE&gt;&lt;P&gt;but this spec won't give the expected output as per your question, as we &lt;STRONG&gt;cannot add the attribute&lt;/STRONG&gt; into main exampledata list.&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;&lt;U&gt;Example1:-&lt;/U&gt;&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="44385-jolt.png" style="width: 3703px;"&gt;&lt;img src="https://community.cloudera.com/t5/image/serverpage/image-id/15718i012619F4A86F9FB3/image-size/medium?v=v2&amp;amp;px=400" role="button" title="44385-jolt.png" alt="44385-jolt.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;by flattening out exampledata then we can add company attribute to the json message as follow.&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;&lt;U&gt;Jolt-spec:-&lt;/U&gt;&lt;/STRONG&gt;&lt;/P&gt;&lt;PRE&gt;[{
"operation": "shift",
"spec": {
"exampledata": {
"*": "&amp;amp;"
}
}
}, {
"operation": "default",
"spec": {
"Company": "${Company}"
}
}]&lt;/PRE&gt;&lt;P&gt;&lt;STRONG&gt;&lt;U&gt;Output:-&lt;/U&gt;&lt;/STRONG&gt;&lt;/P&gt;&lt;PRE&gt;{
"name": "Test",
"age": null,
"ver": null,
"payloadType": "Text",
"payloadData": "adsadsdsdsdsdsdsdsdsds",
"sequenceNum": null,
"timeStamp": "2017-09-22T12:07:29.968Z",
"Company": "Company"
}&lt;/PRE&gt;&lt;P&gt;&lt;STRONG&gt;&lt;U&gt;Example2:-&lt;/U&gt;&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="44383-jolt.png" style="width: 3665px;"&gt;&lt;img src="https://community.cloudera.com/t5/image/serverpage/image-id/15719i6E126D28D9A11980/image-size/medium?v=v2&amp;amp;px=400" role="button" title="44383-jolt.png" alt="44383-jolt.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;If you are using prior version than NiFi 1.2, Then you need to use &lt;STRONG&gt;Replace text Processor&lt;/STRONG&gt; with Below Properties.&lt;/P&gt;&lt;P&gt;Search Value&lt;/P&gt;&lt;DIV&gt;&lt;PRE&gt;}\s+}&lt;/PRE&gt;&lt;/DIV&gt;&lt;P&gt;Replacement Value&lt;/P&gt;&lt;DIV&gt;&lt;PRE&gt;,"company" : "${CompanyName}" } }&lt;/PRE&gt;
&lt;/DIV&gt;&lt;P&gt;Replacement Strategy&lt;/P&gt;&lt;DIV&gt;&lt;PRE&gt;Regex Replace&lt;/PRE&gt;&lt;/DIV&gt;&lt;P&gt;Evaluation Mode&lt;/P&gt;&lt;DIV&gt;&lt;PRE&gt;Entire text&lt;/PRE&gt;
&lt;/DIV&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="44386-replace.png" style="width: 1563px;"&gt;&lt;img src="https://community.cloudera.com/t5/image/serverpage/image-id/15720i084F184BB6A943D0/image-size/medium?v=v2&amp;amp;px=400" role="button" title="44386-replace.png" alt="44386-replace.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;By using this method also we can add the attribute dynamically based on the flowfile attributes to the json message.&lt;/P&gt;</description>
      <pubDate>Sun, 18 Aug 2019 02:09:09 GMT</pubDate>
      <guid>https://community.cloudera.com/t5/Archives-of-Support-Questions/NiFi-How-to-use-JOLT-to-add-json-key-value-dynamically-to/m-p/222330#M72540</guid>
      <dc:creator>Shu_ashu</dc:creator>
      <dc:date>2019-08-18T02:09:09Z</dc:date>
    </item>
    <item>
      <title>Re: NiFi - How to use JOLT to add json key:value  dynamically to the Flowfile content?</title>
      <link>https://community.cloudera.com/t5/Archives-of-Support-Questions/NiFi-How-to-use-JOLT-to-add-json-key-value-dynamically-to/m-p/222331#M72541</link>
      <description>&lt;P&gt;&lt;A rel="user" href="https://community.cloudera.com/users/18929/yaswanthmuppireddy.html" nodeid="18929"&gt;@Shu&lt;/A&gt; - Thanks a lot, it is really helpful.&lt;/P&gt;</description>
      <pubDate>Tue, 12 Dec 2017 17:14:46 GMT</pubDate>
      <guid>https://community.cloudera.com/t5/Archives-of-Support-Questions/NiFi-How-to-use-JOLT-to-add-json-key-value-dynamically-to/m-p/222331#M72541</guid>
      <dc:creator>hegdemahendra</dc:creator>
      <dc:date>2017-12-12T17:14:46Z</dc:date>
    </item>
  </channel>
</rss>

