<?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: Format JSON file using schema in Support Questions</title>
    <link>https://community.cloudera.com/t5/Support-Questions/Format-JSON-file-using-schema/m-p/237935#M199747</link>
    <description>&lt;P&gt;In continuation to the above using Distributed Map Cache to hold a Jolt Spec read from a file, I can confirm that it works.&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;&lt;U&gt;Flow A:&lt;/U&gt;&lt;/STRONG&gt; GetFile (periodically scheduled by CRON) --&amp;gt; PutDistributedMapCache --&amp;gt; LogAttribute:&lt;/P&gt;&lt;P&gt;Jolt spec file contents ( &lt;STRONG&gt;jspec.json &lt;/STRONG&gt;) on disk:&lt;BR /&gt;&lt;BR /&gt;[{"operation":"shift","spec":{"variables":{"0":"variables[0].username","1":"variables[0].active","2":"variables[0].temperature","3":"variables[0].age"},"*":"&amp;amp;"}}]&lt;BR /&gt;&lt;BR /&gt;&lt;STRONG&gt;&lt;U&gt;Note:&lt;/U&gt;&lt;/STRONG&gt;&lt;U&gt; Jolt spec in compact form!!&lt;/U&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;STRONG&gt;GetFile &lt;/STRONG&gt;processor:&lt;/P&gt;&lt;P&gt;File Filter &amp;lt;-- jspec.json&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;PutDistributedMapCache&lt;/STRONG&gt; processor:&lt;/P&gt;&lt;P&gt;Cache Entry Identifier &amp;lt;-- joltspec&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;&lt;U&gt;Flow B:&lt;/U&gt;&lt;/STRONG&gt; GenerateFlowFile --&amp;gt; FetchDistributedMapCache --&amp;gt; JoltTransformJSON&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;&lt;STRONG&gt;GenerateFlowFile&lt;/STRONG&gt; processor:&lt;/P&gt;&lt;P&gt;Custom Text &amp;lt;---&lt;/P&gt;&lt;P&gt;{&lt;!-- --&gt;&lt;/P&gt;&lt;P&gt;  "id" : 123456,&lt;/P&gt;&lt;P&gt;  "ip" : "*",&lt;/P&gt;&lt;P&gt;  "t" : -12.9,&lt;/P&gt;&lt;P&gt;  "T" : -23.8,&lt;/P&gt;&lt;P&gt;  "variables": [&lt;/P&gt;&lt;P&gt;    "user1",&lt;/P&gt;&lt;P&gt;    0,&lt;/P&gt;&lt;P&gt;    12.97,&lt;/P&gt;&lt;P&gt;    23&lt;/P&gt;&lt;P&gt;  ]&lt;/P&gt;&lt;P&gt;}&lt;BR /&gt;&lt;BR /&gt;&lt;STRONG&gt;FetchDistributedMapCache&lt;/STRONG&gt; processor:&lt;/P&gt;&lt;P&gt;Cache Entry Identifier &amp;lt;-- joltspec&lt;BR /&gt;Put Cache Value in Attribute &amp;lt;-- jspec&lt;BR /&gt;&lt;BR /&gt;&lt;STRONG&gt;JoltTransformJSON&lt;/STRONG&gt; processor:&lt;BR /&gt;&lt;BR /&gt;Jolt Transformation DSL &amp;lt;-- Chain&lt;BR /&gt;Jolt Specification &amp;lt;-- ${jspec}&lt;BR /&gt;&lt;BR /&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="109486-capture-001-21062019-074630.jpg" style="width: 1572px;"&gt;&lt;img src="https://community.cloudera.com/t5/image/serverpage/image-id/14169iC7CF6AB0AA2BD08E/image-size/medium?v=v2&amp;amp;px=400" role="button" title="109486-capture-001-21062019-074630.jpg" alt="109486-capture-001-21062019-074630.jpg" /&gt;&lt;/span&gt;&lt;/P&gt;</description>
    <pubDate>Sat, 17 Aug 2019 23:06:47 GMT</pubDate>
    <dc:creator>jerry_pylarinos</dc:creator>
    <dc:date>2019-08-17T23:06:47Z</dc:date>
    <item>
      <title>Format JSON file using schema</title>
      <link>https://community.cloudera.com/t5/Support-Questions/Format-JSON-file-using-schema/m-p/237929#M199741</link>
      <description>&lt;P&gt;Hello,&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;&lt;/P&gt;&lt;P&gt;Receiving from an embedded micro over Ethernet a JSON file of the form:&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;&lt;/P&gt;&lt;P&gt;{&lt;!-- --&gt;&lt;/P&gt;&lt;P style="margin-left:20px"&gt;"id" : 123456,&lt;/P&gt;&lt;P style="margin-left:20px"&gt;"ip" : "*",&lt;/P&gt;&lt;P style="margin-left:20px"&gt;"t"  : -12.9,&lt;/P&gt;&lt;P style="margin-left:20px"&gt;"T"  : -23.8,&lt;/P&gt;&lt;P style="margin-left:20px"&gt;"variables": [&lt;/P&gt;&lt;P style="margin-left:40px"&gt;"user1",&lt;/P&gt;&lt;P style="margin-left:40px"&gt;0,&lt;/P&gt;&lt;P style="margin-left:40px"&gt;12.97,&lt;/P&gt;&lt;P style="margin-left:40px"&gt;23&lt;/P&gt;&lt;P style="margin-left:20px"&gt;]&lt;/P&gt;&lt;P&gt;}&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;&lt;/P&gt;&lt;P&gt;and knowing what each variable represents in the "variables" array as:&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;&lt;/P&gt;&lt;P&gt;"username" : "user1",&lt;/P&gt;&lt;P&gt;"active" : 0,&lt;/P&gt;&lt;P&gt;"temperature" : 12.97,&lt;/P&gt;&lt;P&gt;"age" : 23&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;&lt;/P&gt;&lt;P&gt;How can I update the JSON file with the key name of the variables such that the end result is:&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;&lt;/P&gt;&lt;P&gt;{&lt;!-- --&gt;&lt;/P&gt;&lt;P style="margin-left:20px"&gt;"id" : 123456,&lt;/P&gt;&lt;P style="margin-left:20px"&gt;"ip" : "*",&lt;/P&gt;&lt;P style="margin-left:20px"&gt;"t"  : -12.9,&lt;/P&gt;&lt;P style="margin-left:20px"&gt;"T"  : -23.8,&lt;/P&gt;&lt;P style="margin-left:20px"&gt;"variables": [&lt;/P&gt;&lt;P style="margin-left:40px"&gt;"username" : "user1",&lt;/P&gt;&lt;P style="margin-left:40px"&gt;"active" : 0,&lt;/P&gt;&lt;P style="margin-left:40px"&gt;"temperature" : 12.97,&lt;/P&gt;&lt;P style="margin-left:40px"&gt;"age" : 23&lt;/P&gt;&lt;P style="margin-left:20px"&gt;]&lt;/P&gt;&lt;P&gt;}&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;&lt;/P&gt;&lt;P&gt;and then be able to access these variables with their name?&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;&lt;/P&gt;&lt;P&gt;Thank you.&lt;/P&gt;</description>
      <pubDate>Mon, 08 Apr 2019 00:18:15 GMT</pubDate>
      <guid>https://community.cloudera.com/t5/Support-Questions/Format-JSON-file-using-schema/m-p/237929#M199741</guid>
      <dc:creator>jerry_pylarinos</dc:creator>
      <dc:date>2019-04-08T00:18:15Z</dc:date>
    </item>
    <item>
      <title>Re: Format JSON file using schema</title>
      <link>https://community.cloudera.com/t5/Support-Questions/Format-JSON-file-using-schema/m-p/237930#M199742</link>
      <description>&lt;P&gt;Since you want to change the array of values into key/value pairs, you'll need to put them in an object inside the variables array, so I'm guessing you want a single-element array "variables" containing an object that has the key value pairs. If that's correct, you can use JoltTransformJSON with the following spec, it adds keys for each value in the array based on its order:&lt;/P&gt;&lt;PRE&gt;[
&amp;nbsp; {
&amp;nbsp; &amp;nbsp; "operation": "shift",
&amp;nbsp; &amp;nbsp; "spec": {
&amp;nbsp; &amp;nbsp; &amp;nbsp; "variables": {
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; "0": "variables[0].username",
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; "1": "variables[0].active",
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; "2": "variables[0].temperature",
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; "3": "variables[0].age"
&amp;nbsp; &amp;nbsp; &amp;nbsp; },
&amp;nbsp; &amp;nbsp; &amp;nbsp; "*": "&amp;amp;"
&amp;nbsp; &amp;nbsp; }
&amp;nbsp; }
]&lt;/PRE&gt;&lt;P&gt;&lt;BR /&gt;&lt;/P&gt;&lt;P&gt;This gave me the following output:&lt;/P&gt;&lt;PRE&gt;{
&amp;nbsp; "id" : 123456,
&amp;nbsp; "ip" : "*",
&amp;nbsp; "t" : -12.9,
&amp;nbsp; "T" : -23.8,
&amp;nbsp; "variables" : [ {
&amp;nbsp; &amp;nbsp; "username" : "user1",
&amp;nbsp; &amp;nbsp; "active" : 0,
&amp;nbsp; &amp;nbsp; "temperature" : 12.97,
&amp;nbsp; &amp;nbsp; "age" : 23
&amp;nbsp; } ]
}&lt;/PRE&gt;</description>
      <pubDate>Mon, 08 Apr 2019 20:50:09 GMT</pubDate>
      <guid>https://community.cloudera.com/t5/Support-Questions/Format-JSON-file-using-schema/m-p/237930#M199742</guid>
      <dc:creator>mburgess</dc:creator>
      <dc:date>2019-04-08T20:50:09Z</dc:date>
    </item>
    <item>
      <title>Re: Format JSON file using schema</title>
      <link>https://community.cloudera.com/t5/Support-Questions/Format-JSON-file-using-schema/m-p/237931#M199743</link>
      <description>&lt;P&gt;Yes, excellent!  Thank you &lt;A rel="user" href="https://community.cloudera.com/users/641/mburgess.html" nodeid="641"&gt;@Matt Burgess&lt;/A&gt;!!!&lt;BR /&gt;&lt;BR /&gt;On this topic, I tried reading the jolt spec from a file using the GetFile processor and then extracting the text (jolt spec) using ExtractText and assigning it to a new property such that I can pass the spec to the JoltTransformJSON processor but it doesn't work.  How can this be done?  That is, how can the jolt spec be read from a file instead of configuring the Jolt processor?&lt;BR /&gt;&lt;BR /&gt;Thanking you in advance!&lt;/P&gt;</description>
      <pubDate>Tue, 09 Apr 2019 02:05:17 GMT</pubDate>
      <guid>https://community.cloudera.com/t5/Support-Questions/Format-JSON-file-using-schema/m-p/237931#M199743</guid>
      <dc:creator>jerry_pylarinos</dc:creator>
      <dc:date>2019-04-09T02:05:17Z</dc:date>
    </item>
    <item>
      <title>Re: Format JSON file using schema</title>
      <link>https://community.cloudera.com/t5/Support-Questions/Format-JSON-file-using-schema/m-p/237932#M199744</link>
      <description>&lt;P&gt;This is an open issue (&lt;A rel="noopener noreferrer noopener noreferrer noopener noreferrer noopener noreferrer" href="https://issues.apache.org/jira/browse/NIFI-4957" target="_blank"&gt;NIFI-4957&lt;/A&gt;), I pinged the original author/contributor to get the status of it, if he is not actively working it I can take a look at adding the capability.&lt;/P&gt;</description>
      <pubDate>Wed, 10 Apr 2019 00:58:44 GMT</pubDate>
      <guid>https://community.cloudera.com/t5/Support-Questions/Format-JSON-file-using-schema/m-p/237932#M199744</guid>
      <dc:creator>mburgess</dc:creator>
      <dc:date>2019-04-10T00:58:44Z</dc:date>
    </item>
    <item>
      <title>Re: Format JSON file using schema</title>
      <link>https://community.cloudera.com/t5/Support-Questions/Format-JSON-file-using-schema/m-p/237933#M199745</link>
      <description>&lt;P&gt;That's great Matt.&lt;BR /&gt;Looks like it will become a reality.  Thank you!&lt;/P&gt;</description>
      <pubDate>Wed, 10 Apr 2019 01:27:40 GMT</pubDate>
      <guid>https://community.cloudera.com/t5/Support-Questions/Format-JSON-file-using-schema/m-p/237933#M199745</guid>
      <dc:creator>jerry_pylarinos</dc:creator>
      <dc:date>2019-04-10T01:27:40Z</dc:date>
    </item>
    <item>
      <title>Re: Format JSON file using schema</title>
      <link>https://community.cloudera.com/t5/Support-Questions/Format-JSON-file-using-schema/m-p/237934#M199746</link>
      <description>&lt;P&gt; &lt;A rel="user" href="https://community.hortonworks.com/users/641/mburgess.html"&gt;@Matt Burgess&lt;/A&gt;  I have noticed that there hasn't been progress on this open issue (&lt;A rel="noopener noreferrer noopener noreferrer noopener noreferrer noopener noreferrer noopener noreferrer noopener noreferrer" href="https://issues.apache.org/jira/browse/NIFI-4957" target="_blank"&gt;NIFI-4957&lt;/A&gt;).  Nevertheless I tried placing the Jolt spec in a processor group variable (e.g. jspec) and then using this variable in the JoltTransformJSON processor ( Jolt Specification = ${jspec} ) and it transformed the JSON FlowFile successfully.  Hence an intermediate solution (until &lt;A rel="noopener noreferrer noopener noreferrer noopener noreferrer noopener noreferrer noopener noreferrer noopener noreferrer" href="https://issues.apache.org/jira/browse/NIFI-4957" target="_blank"&gt;NIFI-4957&lt;/A&gt; is resolved) could be to update the processor group variable at the cost of resetting NiFi.&lt;BR /&gt;I will also investigate the process:&lt;BR /&gt;1.- Get Jolt Spec from file ( periodically with a CRON )&lt;BR /&gt;2.- Put FlowFile ( Jolt Spec ) in Distributed Map Cache with e.g. Cache Entry Identifier = jspec&lt;BR /&gt;3.- Fetch Distributed Map Cache (as and when required to transform the JSON FlowFile) and put cache value in attribute jspec&lt;BR /&gt;4.- Assign jspec to Jolt Specification of JoltTransformJSON processor&lt;/P&gt;</description>
      <pubDate>Fri, 21 Jun 2019 05:40:00 GMT</pubDate>
      <guid>https://community.cloudera.com/t5/Support-Questions/Format-JSON-file-using-schema/m-p/237934#M199746</guid>
      <dc:creator>jerry_pylarinos</dc:creator>
      <dc:date>2019-06-21T05:40:00Z</dc:date>
    </item>
    <item>
      <title>Re: Format JSON file using schema</title>
      <link>https://community.cloudera.com/t5/Support-Questions/Format-JSON-file-using-schema/m-p/237935#M199747</link>
      <description>&lt;P&gt;In continuation to the above using Distributed Map Cache to hold a Jolt Spec read from a file, I can confirm that it works.&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;&lt;U&gt;Flow A:&lt;/U&gt;&lt;/STRONG&gt; GetFile (periodically scheduled by CRON) --&amp;gt; PutDistributedMapCache --&amp;gt; LogAttribute:&lt;/P&gt;&lt;P&gt;Jolt spec file contents ( &lt;STRONG&gt;jspec.json &lt;/STRONG&gt;) on disk:&lt;BR /&gt;&lt;BR /&gt;[{"operation":"shift","spec":{"variables":{"0":"variables[0].username","1":"variables[0].active","2":"variables[0].temperature","3":"variables[0].age"},"*":"&amp;amp;"}}]&lt;BR /&gt;&lt;BR /&gt;&lt;STRONG&gt;&lt;U&gt;Note:&lt;/U&gt;&lt;/STRONG&gt;&lt;U&gt; Jolt spec in compact form!!&lt;/U&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;STRONG&gt;GetFile &lt;/STRONG&gt;processor:&lt;/P&gt;&lt;P&gt;File Filter &amp;lt;-- jspec.json&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;PutDistributedMapCache&lt;/STRONG&gt; processor:&lt;/P&gt;&lt;P&gt;Cache Entry Identifier &amp;lt;-- joltspec&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;&lt;U&gt;Flow B:&lt;/U&gt;&lt;/STRONG&gt; GenerateFlowFile --&amp;gt; FetchDistributedMapCache --&amp;gt; JoltTransformJSON&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;&lt;STRONG&gt;GenerateFlowFile&lt;/STRONG&gt; processor:&lt;/P&gt;&lt;P&gt;Custom Text &amp;lt;---&lt;/P&gt;&lt;P&gt;{&lt;!-- --&gt;&lt;/P&gt;&lt;P&gt;  "id" : 123456,&lt;/P&gt;&lt;P&gt;  "ip" : "*",&lt;/P&gt;&lt;P&gt;  "t" : -12.9,&lt;/P&gt;&lt;P&gt;  "T" : -23.8,&lt;/P&gt;&lt;P&gt;  "variables": [&lt;/P&gt;&lt;P&gt;    "user1",&lt;/P&gt;&lt;P&gt;    0,&lt;/P&gt;&lt;P&gt;    12.97,&lt;/P&gt;&lt;P&gt;    23&lt;/P&gt;&lt;P&gt;  ]&lt;/P&gt;&lt;P&gt;}&lt;BR /&gt;&lt;BR /&gt;&lt;STRONG&gt;FetchDistributedMapCache&lt;/STRONG&gt; processor:&lt;/P&gt;&lt;P&gt;Cache Entry Identifier &amp;lt;-- joltspec&lt;BR /&gt;Put Cache Value in Attribute &amp;lt;-- jspec&lt;BR /&gt;&lt;BR /&gt;&lt;STRONG&gt;JoltTransformJSON&lt;/STRONG&gt; processor:&lt;BR /&gt;&lt;BR /&gt;Jolt Transformation DSL &amp;lt;-- Chain&lt;BR /&gt;Jolt Specification &amp;lt;-- ${jspec}&lt;BR /&gt;&lt;BR /&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="109486-capture-001-21062019-074630.jpg" style="width: 1572px;"&gt;&lt;img src="https://community.cloudera.com/t5/image/serverpage/image-id/14169iC7CF6AB0AA2BD08E/image-size/medium?v=v2&amp;amp;px=400" role="button" title="109486-capture-001-21062019-074630.jpg" alt="109486-capture-001-21062019-074630.jpg" /&gt;&lt;/span&gt;&lt;/P&gt;</description>
      <pubDate>Sat, 17 Aug 2019 23:06:47 GMT</pubDate>
      <guid>https://community.cloudera.com/t5/Support-Questions/Format-JSON-file-using-schema/m-p/237935#M199747</guid>
      <dc:creator>jerry_pylarinos</dc:creator>
      <dc:date>2019-08-17T23:06:47Z</dc:date>
    </item>
    <item>
      <title>Re: Format JSON file using schema</title>
      <link>https://community.cloudera.com/t5/Support-Questions/Format-JSON-file-using-schema/m-p/317319#M227117</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://community.cloudera.com/t5/user/viewprofilepage/user-id/45618"&gt;@jerry_pylarinos&lt;/a&gt;&amp;nbsp;and&amp;nbsp;&lt;a href="https://community.cloudera.com/t5/user/viewprofilepage/user-id/38301"&gt;@mburgess&lt;/a&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I am seeing weird behavior in the same scenario but the only difference is my spec has expression language inside Jspec and it never resolved after pulling from the cache and passing as an attribute to jolttransform. Is that a bug?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;like if you jspec.json has&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;[
 {
    "operation": "modify-overwrite-beta",
    "spec": {
		"id": "${UUID()}"
        }
   }
]&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;and your generate flow file has&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;{
     "id" : "anyname"
}&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;You result looks like this&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;{
  "id":"${UUID()}"
}&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;How to evaluate expression langauge here?&lt;/P&gt;</description>
      <pubDate>Fri, 28 May 2021 22:40:59 GMT</pubDate>
      <guid>https://community.cloudera.com/t5/Support-Questions/Format-JSON-file-using-schema/m-p/317319#M227117</guid>
      <dc:creator>tpatel</dc:creator>
      <dc:date>2021-05-28T22:40:59Z</dc:date>
    </item>
  </channel>
</rss>

