<?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: Update Json field via Nifi in Support Questions</title>
    <link>https://community.cloudera.com/t5/Support-Questions/Update-Json-field-via-Nifi/m-p/321086#M228258</link>
    <description>&lt;P&gt;Hi&amp;nbsp;&lt;A href="https://community.cloudera.com/t5/user/viewprofilepage/user-id/90395" target="_blank" rel="noopener"&gt;&lt;SPAN&gt;alexmarco,&lt;/SPAN&gt;&lt;/A&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;If your final json format is fixed and input json also coming in same format always with values different then you extract keyword value (foo or new value) into flowfile attribute and you can use attribute in following replacetext processor to pass the value .&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="SampleJson.PNG" style="width: 334px;"&gt;&lt;img src="https://community.cloudera.com/t5/image/serverpage/image-id/31919iD39FA87FE4FD1C1A/image-size/large?v=v2&amp;amp;px=999" role="button" title="SampleJson.PNG" alt="SampleJson.PNG" /&gt;&lt;/span&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;ExtractText processor --&amp;gt; UpdateAttributeProcessor --&amp;gt; ReplaceText Processor&lt;/P&gt;&lt;P&gt;1. Add a new property(&lt;SPAN class="table-cell"&gt;keyword_value)&lt;/SPAN&gt; in&amp;nbsp;ExtractText and value/expression should be below&lt;/P&gt;&lt;DIV class="slick-cell l0 r0"&gt;&lt;SPAN class="table-cell"&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;SPAN&gt;("keyword":.*)&lt;/SPAN&gt;&lt;/DIV&gt;&lt;P&gt;2. Remove space,double quotes from the extracted keyword_value attribute in&amp;nbsp;UpdateAttributeProcessor. (You can add the updateattribute logic directly in Replacetext processor itself for retrieving the keyword_value also as ReplaceText processor supports NiFi expression language. Its optional and you avoid Updateattribute processor in this flow then if you chose )&lt;/P&gt;&lt;P&gt;3. Append the keyword_value in ReplaceText processor (keep the final json ) as in sample .&lt;/P&gt;&lt;P&gt;4. Connect the success flow into Invokehttp processor.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;*&amp;nbsp;CreateKeywordvalueAttribute (Extract processor) expression below&amp;nbsp; :&amp;nbsp;("keyword":.*)&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="CreateKeywordvalueAttribute.PNG" style="width: 997px;"&gt;&lt;img src="https://community.cloudera.com/t5/image/serverpage/image-id/31920iA23EC0A46A1A2477/image-size/large?v=v2&amp;amp;px=999" role="button" title="CreateKeywordvalueAttribute.PNG" alt="CreateKeywordvalueAttribute.PNG" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;* Updateattributeprocessor&amp;nbsp; ${keyword_value:substringAfter(':'):trim():replace('"', '')}&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="ParseKeywordValueAttribute.PNG" style="width: 999px;"&gt;&lt;img src="https://community.cloudera.com/t5/image/serverpage/image-id/31921iADBF474C51C31E15/image-size/large?v=v2&amp;amp;px=999" role="button" title="ParseKeywordValueAttribute.PNG" alt="ParseKeywordValueAttribute.PNG" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;* FinalReplaceText processor : Place the below JSON into&amp;nbsp;&lt;SPAN&gt;Replacement Value section of the processor&amp;nbsp;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;{
    "requests": [
        {
            "source": "blablabla",
            "params": {
                "keywords": [
                    "${keyword_value}"
                ],
                "sub-field1": "1"
           }
        }
    ],
    "field1": "1",
    "field2": "2",
    "field3": false
}&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;I have attached the sample tested flow(.xml) for your reference .&amp;nbsp;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;Please accept the solution if it works as expected.&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;Thanks&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;Adhi&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;/P&gt;&lt;DIV class="dcxa-lithium-author-rank"&gt;&amp;nbsp;&lt;/DIV&gt;</description>
    <pubDate>Fri, 16 Jul 2021 16:00:24 GMT</pubDate>
    <dc:creator>adhishankarit</dc:creator>
    <dc:date>2021-07-16T16:00:24Z</dc:date>
    <item>
      <title>Update Json field via Nifi</title>
      <link>https://community.cloudera.com/t5/Support-Questions/Update-Json-field-via-Nifi/m-p/321075#M228252</link>
      <description>&lt;P&gt;I have a json like this coming from an input port:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;{
"url": "blablabla",
"keyword": "foo"
}&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;then I have to generate a new json to pass to a post call. The new json is something like this:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;{
    "requests": [
        {
            "source": "blablabla",
            "params": {
                "keywords": [
                    "something"
                ],
                "sub-field1": "1"
           }
        }
    ],
    "field1": "1",
    "field2": "2",
    "field3": false
}&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;where the array keywords should be replaced with a new array with the value of the previous Json ("foo"). The resulting is:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;{
    "requests": [
        {
            "source": "blablabla",
            "params": {
                "keywords": [
                    "foo"
                ],
                "sub-field1": "1"
           }
        }
    ],
    "field1": "1",
    "field2": "2",
    "field3": false
}&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;then i pass this json to a invokehttp to call the post.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Could you please explain me how to generate this flow?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;thanks&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 16 Jul 2021 12:41:25 GMT</pubDate>
      <guid>https://community.cloudera.com/t5/Support-Questions/Update-Json-field-via-Nifi/m-p/321075#M228252</guid>
      <dc:creator>alexmarco</dc:creator>
      <dc:date>2021-07-16T12:41:25Z</dc:date>
    </item>
    <item>
      <title>Re: Update Json field via Nifi</title>
      <link>https://community.cloudera.com/t5/Support-Questions/Update-Json-field-via-Nifi/m-p/321086#M228258</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;A href="https://community.cloudera.com/t5/user/viewprofilepage/user-id/90395" target="_blank" rel="noopener"&gt;&lt;SPAN&gt;alexmarco,&lt;/SPAN&gt;&lt;/A&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;If your final json format is fixed and input json also coming in same format always with values different then you extract keyword value (foo or new value) into flowfile attribute and you can use attribute in following replacetext processor to pass the value .&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="SampleJson.PNG" style="width: 334px;"&gt;&lt;img src="https://community.cloudera.com/t5/image/serverpage/image-id/31919iD39FA87FE4FD1C1A/image-size/large?v=v2&amp;amp;px=999" role="button" title="SampleJson.PNG" alt="SampleJson.PNG" /&gt;&lt;/span&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;ExtractText processor --&amp;gt; UpdateAttributeProcessor --&amp;gt; ReplaceText Processor&lt;/P&gt;&lt;P&gt;1. Add a new property(&lt;SPAN class="table-cell"&gt;keyword_value)&lt;/SPAN&gt; in&amp;nbsp;ExtractText and value/expression should be below&lt;/P&gt;&lt;DIV class="slick-cell l0 r0"&gt;&lt;SPAN class="table-cell"&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;SPAN&gt;("keyword":.*)&lt;/SPAN&gt;&lt;/DIV&gt;&lt;P&gt;2. Remove space,double quotes from the extracted keyword_value attribute in&amp;nbsp;UpdateAttributeProcessor. (You can add the updateattribute logic directly in Replacetext processor itself for retrieving the keyword_value also as ReplaceText processor supports NiFi expression language. Its optional and you avoid Updateattribute processor in this flow then if you chose )&lt;/P&gt;&lt;P&gt;3. Append the keyword_value in ReplaceText processor (keep the final json ) as in sample .&lt;/P&gt;&lt;P&gt;4. Connect the success flow into Invokehttp processor.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;*&amp;nbsp;CreateKeywordvalueAttribute (Extract processor) expression below&amp;nbsp; :&amp;nbsp;("keyword":.*)&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="CreateKeywordvalueAttribute.PNG" style="width: 997px;"&gt;&lt;img src="https://community.cloudera.com/t5/image/serverpage/image-id/31920iA23EC0A46A1A2477/image-size/large?v=v2&amp;amp;px=999" role="button" title="CreateKeywordvalueAttribute.PNG" alt="CreateKeywordvalueAttribute.PNG" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;* Updateattributeprocessor&amp;nbsp; ${keyword_value:substringAfter(':'):trim():replace('"', '')}&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="ParseKeywordValueAttribute.PNG" style="width: 999px;"&gt;&lt;img src="https://community.cloudera.com/t5/image/serverpage/image-id/31921iADBF474C51C31E15/image-size/large?v=v2&amp;amp;px=999" role="button" title="ParseKeywordValueAttribute.PNG" alt="ParseKeywordValueAttribute.PNG" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;* FinalReplaceText processor : Place the below JSON into&amp;nbsp;&lt;SPAN&gt;Replacement Value section of the processor&amp;nbsp;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;{
    "requests": [
        {
            "source": "blablabla",
            "params": {
                "keywords": [
                    "${keyword_value}"
                ],
                "sub-field1": "1"
           }
        }
    ],
    "field1": "1",
    "field2": "2",
    "field3": false
}&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;I have attached the sample tested flow(.xml) for your reference .&amp;nbsp;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;Please accept the solution if it works as expected.&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;Thanks&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;Adhi&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;/P&gt;&lt;DIV class="dcxa-lithium-author-rank"&gt;&amp;nbsp;&lt;/DIV&gt;</description>
      <pubDate>Fri, 16 Jul 2021 16:00:24 GMT</pubDate>
      <guid>https://community.cloudera.com/t5/Support-Questions/Update-Json-field-via-Nifi/m-p/321086#M228258</guid>
      <dc:creator>adhishankarit</dc:creator>
      <dc:date>2021-07-16T16:00:24Z</dc:date>
    </item>
    <item>
      <title>Re: Update Json field via Nifi</title>
      <link>https://community.cloudera.com/t5/Support-Questions/Update-Json-field-via-Nifi/m-p/321130#M228278</link>
      <description>&lt;P&gt;Hi &lt;a href="https://community.cloudera.com/t5/user/viewprofilepage/user-id/57238"&gt;@adhishankarit&lt;/a&gt;,&amp;nbsp;thanks for your response....one question...I don't see the link to download the xml..where i can find it?&lt;/P&gt;</description>
      <pubDate>Mon, 19 Jul 2021 07:57:44 GMT</pubDate>
      <guid>https://community.cloudera.com/t5/Support-Questions/Update-Json-field-via-Nifi/m-p/321130#M228278</guid>
      <dc:creator>alexmarco</dc:creator>
      <dc:date>2021-07-19T07:57:44Z</dc:date>
    </item>
    <item>
      <title>Re: Update Json field via Nifi</title>
      <link>https://community.cloudera.com/t5/Support-Questions/Update-Json-field-via-Nifi/m-p/321142#M228288</link>
      <description>&lt;P&gt;&lt;SPAN&gt;&amp;nbsp;Hi&amp;nbsp;&lt;/SPAN&gt;&lt;A href="https://community.cloudera.com/t5/user/viewprofilepage/user-id/90395" target="_blank" rel="noopener"&gt;&lt;SPAN&gt;alexmarco,&lt;/SPAN&gt;&lt;/A&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;I did not find the 'Upload/Attach' option to upload the template file . Could you please follow the steps/screenshots mentioned , it should work for your example well.&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;thanks&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 19 Jul 2021 14:22:56 GMT</pubDate>
      <guid>https://community.cloudera.com/t5/Support-Questions/Update-Json-field-via-Nifi/m-p/321142#M228288</guid>
      <dc:creator>adhishankarit</dc:creator>
      <dc:date>2021-07-19T14:22:56Z</dc:date>
    </item>
  </channel>
</rss>

