<?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 AttributesToJSON makes everything strings in Support Questions</title>
    <link>https://community.cloudera.com/t5/Support-Questions/Nifi-AttributesToJSON-makes-everything-strings/m-p/316812#M226902</link>
    <description>&lt;P&gt;Not all credit goes to me but I was pointed to a better simpler way to achieve this. There are 2 ways.&lt;BR /&gt;&lt;BR /&gt;Solution 1 - and the simplest and elegant&lt;BR /&gt;Use Nifi JoltTransformJSON Processor. The processor can make use of Nifi expression language and attributes in both&amp;nbsp;&lt;SPAN&gt;left or right hand side of the specification syntax. This allows you to quickly use the JOLT default spec to add new fields (from flow-file attributes) to a new or existing JSON.&lt;BR /&gt;&lt;BR /&gt;Ex:&lt;BR /&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;{"customer_id": 1234567, "vckey_list": ["test value"]}&lt;/LI-CODE&gt;&lt;P&gt;&lt;SPAN&gt;&amp;nbsp;both of those fields values are stored in flow-file attributes as a result of a&amp;nbsp;EvaluateJSONPath operation. Assume "customer_id_attr" and ""vckey_list_attr". We can simply generate a new JSON from those flow-file attributes with the "default" jolt spec and the right hand syntax. You can even add addition expression language functions to the processing&lt;BR /&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;[
  {
    "operation": "default",
    "spec": {
      "customer_id": ${customer_id_attr},
      "vckey_list": ${vckey_list_attr:toLower()}
    }
  }
]&lt;/LI-CODE&gt;&lt;P&gt;&lt;SPAN&gt;This worked for me even when storing the entire JSON, path of "$", in a flow-file attribute.&lt;BR /&gt;&lt;BR /&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;Solution 2 - complicated and uglier&lt;BR /&gt;Use a sequence Nifi ReplaceText Processor. First use a&amp;nbsp;ReplaceText processor to append the desired&amp;nbsp;flow-file attribute to the file-content.&lt;BR /&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="tazzio_0-1621516138039.png" style="width: 400px;"&gt;&lt;img src="https://community.cloudera.com/t5/image/serverpage/image-id/31238iBC1F47F2A4B7A7CA/image-size/medium?v=v2&amp;amp;px=400" role="button" title="tazzio_0-1621516138039.png" alt="tazzio_0-1621516138039.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;If you are generating a totally new JSON, this would do it. If you are trying to modify an existing one, you would need to first append the desired keys, than use ReplaceText again to properly format as a new key in the existing JSON, from&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;{"original_json_key": original_json_obj}{"customer_id": 1234567, "vckey_list": ["test value"]}&lt;/LI-CODE&gt;&lt;P&gt;to&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;{"original_json_key": original_json_obj, "customer_id": 1234567, "vckey_list": ["test value"]}&lt;/LI-CODE&gt;&lt;P&gt;using&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="tazzio_1-1621516605995.png" style="width: 400px;"&gt;&lt;img src="https://community.cloudera.com/t5/image/serverpage/image-id/31239iFD91CAB0F50469A5/image-size/medium?v=v2&amp;amp;px=400" role="button" title="tazzio_1-1621516605995.png" alt="tazzio_1-1621516605995.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;Then use JOLT to do further processing (that's why Sol 1 always makes sense)&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;&lt;BR /&gt;Hope this helps, spent about half a day figuring out the 2nd Solution and was pointed to Solution 1 by someone with more experience in Nifi&lt;/SPAN&gt;&lt;/P&gt;</description>
    <pubDate>Thu, 20 May 2021 13:17:50 GMT</pubDate>
    <dc:creator>tazzio</dc:creator>
    <dc:date>2021-05-20T13:17:50Z</dc:date>
  </channel>
</rss>

