<?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: JSONtoSQL with JSON containing an array with a variable amount of values in Archives of Support Questions (Read Only)</title>
    <link>https://community.cloudera.com/t5/Archives-of-Support-Questions/JSONtoSQL-with-JSON-containing-an-array-with-a-variable/m-p/142894#M56427</link>
    <description>&lt;A rel="user" href="https://community.cloudera.com/users/16478/christianlenz.html" nodeid="16478"&gt;@Chris Lenz&lt;/A&gt;&lt;P&gt;This should be possible using JOLTJsonTransform processor. &lt;/P&gt;&lt;P&gt;&lt;A href="https://nifi.apache.org/docs/nifi-docs/components/org.apache.nifi.processors.standard.JoltTransformJSON/index.html" target="_blank"&gt;https://nifi.apache.org/docs/nifi-docs/components/org.apache.nifi.processors.standard.JoltTransformJSON/index.html&lt;/A&gt;&lt;/P&gt;&lt;P&gt;It helps you flatten your json. Output still remains json. It's a little more complex to learn so might take a day or two to understand all of it but its very handy. You should look at both the links below:&lt;/P&gt;&lt;P&gt;&lt;A href="https://docs.google.com/presentation/d/1sAiuiFC4Lzz4-064sg1p8EQt2ev0o442MfEbvrpD1ls/edit#slide=id.g9680451c_043" target="_blank"&gt;https://docs.google.com/presentation/d/1sAiuiFC4Lzz4-064sg1p8EQt2ev0o442MfEbvrpD1ls/edit#slide=id.g9680451c_043&lt;/A&gt;&lt;/P&gt;&lt;P&gt;&lt;A href="https://github.com/bazaarvoice/jolt" target="_blank"&gt;https://github.com/bazaarvoice/jolt&lt;/A&gt; &lt;/P&gt;</description>
    <pubDate>Tue, 07 Mar 2017 22:38:24 GMT</pubDate>
    <dc:creator>mqureshi</dc:creator>
    <dc:date>2017-03-07T22:38:24Z</dc:date>
    <item>
      <title>JSONtoSQL with JSON containing an array with a variable amount of values</title>
      <link>https://community.cloudera.com/t5/Archives-of-Support-Questions/JSONtoSQL-with-JSON-containing-an-array-with-a-variable/m-p/142893#M56426</link>
      <description>&lt;P&gt;
	Hi,&lt;/P&gt;&lt;P&gt;
	I want to put the following JSON-File into a DB-table:&lt;/P&gt;
&lt;PRE&gt;{  
   "Time":"03/07/2017 11:45:46.365",
   "Subscription":"1234567",
   "ServiceCodes":[  
      "SERVICE_CODE1",
      "SERVICE_CODE2",
      "SERVICE_CODE3",
      "SERVICE_CODE4"
   ]
}
&lt;/PRE&gt;&lt;P&gt;
	The amount of servicecodes is variable, so there are JSONs, which consists 4 ServiceCodes but there are also some which just have 1 to 3 servicecodes. &lt;/P&gt;&lt;P&gt;
	It would be perfect to put it in the table having one row per Servicecode:&lt;/P&gt;
&lt;TABLE&gt;
&lt;TBODY&gt;
&lt;TR&gt;
	&lt;TD&gt;
		TIME
	&lt;/TD&gt;
	&lt;TD&gt;
		SUBSCRIPTION
	&lt;/TD&gt;
	&lt;TD&gt;
		SERVICECODE
	&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
	&lt;TD&gt;
03/07/2017 11:45:46.365
	&lt;/TD&gt;
	&lt;TD&gt;
1234567
	&lt;/TD&gt;
	&lt;TD&gt;
SERVICE_CODE1
	&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
	&lt;TD&gt;
03/07/2017 11:45:46.365
	&lt;/TD&gt;
	&lt;TD&gt;
1234567
	&lt;/TD&gt;
	&lt;TD&gt;
SERVICE_CODE2
		

	&lt;/TD&gt;
&lt;/TR&gt;
&lt;/TBODY&gt;
&lt;/TABLE&gt;&lt;P&gt;
	But I don't know if this is possible with nifi. &lt;/P&gt;&lt;P&gt;
	If not, I would be ok with having it as a comma-seperated list:&lt;/P&gt;
&lt;TABLE&gt;
&lt;TBODY&gt;
&lt;TR&gt;
	&lt;TD&gt;
		TIME
	&lt;/TD&gt;
	&lt;TD&gt;
		SUBSCRIPTION
	&lt;/TD&gt;
	&lt;TD&gt;
		SERVICECODE
	&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
	&lt;TD&gt;
		&lt;P&gt;
			03/07/2017 11:45:46.365
		&lt;/P&gt;
	&lt;/TD&gt;
	&lt;TD&gt;
		&lt;P&gt;
			1234567
		&lt;/P&gt;
	&lt;/TD&gt;
	&lt;TD&gt;
		&lt;P&gt;
			SERVICE_CODE1,
		&lt;/P&gt;
		&lt;P&gt;
			SERVICE_CODE2,
		&lt;/P&gt;
		&lt;P&gt;
			SERVICE_CODE3,
		&lt;/P&gt;
		&lt;P&gt;
			SERVICE_CODE4
		&lt;/P&gt;
	&lt;/TD&gt;
&lt;/TR&gt;
&lt;/TBODY&gt;
&lt;/TABLE&gt;&lt;P&gt;At the moment I am using a CONVERTJSONTOSQL-Processor in Combination with a PUTSQL-Processor. This is working for TIME and SUBSCRIPTION, but SERVICECODE is always empty.  In the OracleDB ServiceCode is a varchar2(250), but this could be changed.&lt;/P&gt;&lt;P&gt;Any suggestions how to do this?&lt;/P&gt;&lt;P&gt;Thanks a lot for your help.&lt;/P&gt;&lt;P&gt;Rgrds,&lt;/P&gt;&lt;P&gt;Chris&lt;/P&gt;</description>
      <pubDate>Tue, 07 Mar 2017 22:02:58 GMT</pubDate>
      <guid>https://community.cloudera.com/t5/Archives-of-Support-Questions/JSONtoSQL-with-JSON-containing-an-array-with-a-variable/m-p/142893#M56426</guid>
      <dc:creator>Christian_Lenz</dc:creator>
      <dc:date>2017-03-07T22:02:58Z</dc:date>
    </item>
    <item>
      <title>Re: JSONtoSQL with JSON containing an array with a variable amount of values</title>
      <link>https://community.cloudera.com/t5/Archives-of-Support-Questions/JSONtoSQL-with-JSON-containing-an-array-with-a-variable/m-p/142894#M56427</link>
      <description>&lt;A rel="user" href="https://community.cloudera.com/users/16478/christianlenz.html" nodeid="16478"&gt;@Chris Lenz&lt;/A&gt;&lt;P&gt;This should be possible using JOLTJsonTransform processor. &lt;/P&gt;&lt;P&gt;&lt;A href="https://nifi.apache.org/docs/nifi-docs/components/org.apache.nifi.processors.standard.JoltTransformJSON/index.html" target="_blank"&gt;https://nifi.apache.org/docs/nifi-docs/components/org.apache.nifi.processors.standard.JoltTransformJSON/index.html&lt;/A&gt;&lt;/P&gt;&lt;P&gt;It helps you flatten your json. Output still remains json. It's a little more complex to learn so might take a day or two to understand all of it but its very handy. You should look at both the links below:&lt;/P&gt;&lt;P&gt;&lt;A href="https://docs.google.com/presentation/d/1sAiuiFC4Lzz4-064sg1p8EQt2ev0o442MfEbvrpD1ls/edit#slide=id.g9680451c_043" target="_blank"&gt;https://docs.google.com/presentation/d/1sAiuiFC4Lzz4-064sg1p8EQt2ev0o442MfEbvrpD1ls/edit#slide=id.g9680451c_043&lt;/A&gt;&lt;/P&gt;&lt;P&gt;&lt;A href="https://github.com/bazaarvoice/jolt" target="_blank"&gt;https://github.com/bazaarvoice/jolt&lt;/A&gt; &lt;/P&gt;</description>
      <pubDate>Tue, 07 Mar 2017 22:38:24 GMT</pubDate>
      <guid>https://community.cloudera.com/t5/Archives-of-Support-Questions/JSONtoSQL-with-JSON-containing-an-array-with-a-variable/m-p/142894#M56427</guid>
      <dc:creator>mqureshi</dc:creator>
      <dc:date>2017-03-07T22:38:24Z</dc:date>
    </item>
    <item>
      <title>Re: JSONtoSQL with JSON containing an array with a variable amount of values</title>
      <link>https://community.cloudera.com/t5/Archives-of-Support-Questions/JSONtoSQL-with-JSON-containing-an-array-with-a-variable/m-p/142895#M56428</link>
      <description>&lt;P&gt;To put each of the ServiceCodes values into its own "row", you can use &lt;A target="_blank" href="https://nifi.apache.org/docs/nifi-docs/components/org.apache.nifi.processors.standard.JoltTransformJSON/index.html"&gt;JoltTransformJSON&lt;/A&gt; with the following shift specification:&lt;/P&gt;&lt;PRE&gt;{
    "operation": "shift",
    "spec": {
      "ServiceCodes": {
        "*": {
          "@(2,Time)": "[&amp;amp;].Time",
          "@(2,Subscription)": "[&amp;amp;].Subscription",
          "@": "[&amp;amp;].ServiceCode"
        }
      }
    }
  }&lt;/PRE&gt;&lt;P&gt;Given your input above, it will produce the following:&lt;/P&gt;&lt;PRE&gt;[ {
  "ServiceCode" : "SERVICE_CODE1",
  "Subscription" : "1234567",
  "Time" : "03/07/2017 11:45:46.365"
}, {
  "ServiceCode" : "SERVICE_CODE2",
  "Subscription" : "1234567",
  "Time" : "03/07/2017 11:45:46.365"
}, {
  "ServiceCode" : "SERVICE_CODE3",
  "Subscription" : "1234567",
  "Time" : "03/07/2017 11:45:46.365"
}, {
  "ServiceCode" : "SERVICE_CODE4",
  "Subscription" : "1234567",
  "Time" : "03/07/2017 11:45:46.365"
} ]&lt;/PRE&gt;&lt;P&gt;This might be able to go directly into ConvertJSONToSQL, but if it doesn't, you can use &lt;A target="_blank" href="https://nifi.apache.org/docs/nifi-docs/components/org.apache.nifi.processors.standard.SplitJson/index.html"&gt;SplitJSON&lt;/A&gt; with $[*] or $.* as the JSON Path expression, and it will divide the array up into one flow file per object in the array. Then you should be able to transform it to SQL.&lt;/P&gt;</description>
      <pubDate>Tue, 07 Mar 2017 22:42:41 GMT</pubDate>
      <guid>https://community.cloudera.com/t5/Archives-of-Support-Questions/JSONtoSQL-with-JSON-containing-an-array-with-a-variable/m-p/142895#M56428</guid>
      <dc:creator>mburgess</dc:creator>
      <dc:date>2017-03-07T22:42:41Z</dc:date>
    </item>
    <item>
      <title>Re: JSONtoSQL with JSON containing an array with a variable amount of values</title>
      <link>https://community.cloudera.com/t5/Archives-of-Support-Questions/JSONtoSQL-with-JSON-containing-an-array-with-a-variable/m-p/142896#M56429</link>
      <description>&lt;P&gt;Perfect answer. Worked out perfectly. Thanks a lot.&lt;/P&gt;</description>
      <pubDate>Wed, 08 Mar 2017 16:59:38 GMT</pubDate>
      <guid>https://community.cloudera.com/t5/Archives-of-Support-Questions/JSONtoSQL-with-JSON-containing-an-array-with-a-variable/m-p/142896#M56429</guid>
      <dc:creator>Christian_Lenz</dc:creator>
      <dc:date>2017-03-08T16:59:38Z</dc:date>
    </item>
    <item>
      <title>Re: JSONtoSQL with JSON containing an array with a variable amount of values</title>
      <link>https://community.cloudera.com/t5/Archives-of-Support-Questions/JSONtoSQL-with-JSON-containing-an-array-with-a-variable/m-p/142897#M56430</link>
      <description>&lt;P&gt;Thanks. Managed to do so with the Jolt Processor.&lt;/P&gt;</description>
      <pubDate>Wed, 08 Mar 2017 17:00:31 GMT</pubDate>
      <guid>https://community.cloudera.com/t5/Archives-of-Support-Questions/JSONtoSQL-with-JSON-containing-an-array-with-a-variable/m-p/142897#M56430</guid>
      <dc:creator>Christian_Lenz</dc:creator>
      <dc:date>2017-03-08T17:00:31Z</dc:date>
    </item>
  </channel>
</rss>

