<?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: Convert json to multiple insert sql format in Support Questions</title>
    <link>https://community.cloudera.com/t5/Support-Questions/Convert-json-to-multiple-insert-sql-format/m-p/366802#M239677</link>
    <description>&lt;P&gt;What do you mean by it gave you "so many flowfiles". If you follow the same jolt spec and split processors configuration as I provided it should give you the exact amount flowfiles similar to the number of ACT in the original input. Can you provide more details?&lt;/P&gt;</description>
    <pubDate>Thu, 23 Mar 2023 12:58:35 GMT</pubDate>
    <dc:creator>SAMSAL</dc:creator>
    <dc:date>2023-03-23T12:58:35Z</dc:date>
    <item>
      <title>Convert json to multiple insert sql format</title>
      <link>https://community.cloudera.com/t5/Support-Questions/Convert-json-to-multiple-insert-sql-format/m-p/366411#M239575</link>
      <description>&lt;P&gt;Hi All,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Greetings!&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Assume that I have a data flow, and the final result is inserting to the SQL database (Microsoft), but the step before! I have the following JSON format for each flow file content as following:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="java"&gt;{
  "sbrActivityType" : {
    "1" : "ACT+A",
    "3" : "ACT+A",
    "2" : "ACT+X",
    "5" : "ACT+X",
    "4" : "ACT+X"
  },
  "sbrDateTime" : "Sun Mar 19 13:45:15 AST 2023"
}&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Then, my desired output format look like the following:&lt;/P&gt;&lt;P&gt;INSERT INTO sbrTestNifiData (sbrActivityType, sbrDateTime) VALUES (?, ?)&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;So, it does not insert correctly to my database table which is looks like the following:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="java"&gt;CREATE TABLE [dbo].[sbrTestNifiData](
	[sbrId] [int] IDENTITY(1,1) NOT NULL primary key,
	[sbrActivityType] [varchar](50) NULL,
	[sbrDateTime] [varchar](50) NULL
);&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;So, it should inserted to my database table as a five records:&lt;/P&gt;&lt;TABLE border="1" width="95.26145241477275%"&gt;&lt;TBODY&gt;&lt;TR&gt;&lt;TD width="33.333333333333336%" height="30px"&gt;sbrId&lt;/TD&gt;&lt;TD width="33.333333333333336%" height="30px"&gt;sbrActivityType&lt;/TD&gt;&lt;TD width="33.333333333333336%" height="30px"&gt;sbrDateTime&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD width="33.333333333333336%" height="30px"&gt;&lt;FONT size="2"&gt;1&lt;/FONT&gt;&lt;/TD&gt;&lt;TD width="33.333333333333336%" height="30px"&gt;&lt;FONT size="2"&gt;ACT+A&lt;/FONT&gt;&lt;/TD&gt;&lt;TD width="33.333333333333336%" height="30px"&gt;&lt;FONT size="2"&gt;Sun Mar 19 11:56:40 AST 2023&lt;/FONT&gt;&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD width="33.333333333333336%" height="30px"&gt;&lt;FONT size="2"&gt;2&lt;/FONT&gt;&lt;/TD&gt;&lt;TD width="33.333333333333336%" height="30px"&gt;&lt;FONT size="2"&gt;ACT+A&lt;/FONT&gt;&lt;/TD&gt;&lt;TD width="33.333333333333336%" height="30px"&gt;&lt;FONT size="2"&gt;Sun Mar 19 11:56:40 AST 2023&lt;/FONT&gt;&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD width="33.333333333333336%" height="30px"&gt;&lt;FONT size="2"&gt;3&lt;/FONT&gt;&lt;/TD&gt;&lt;TD width="33.333333333333336%" height="30px"&gt;&lt;FONT size="2"&gt;ACT+X&lt;/FONT&gt;&lt;/TD&gt;&lt;TD width="33.333333333333336%" height="30px"&gt;&lt;FONT size="2"&gt;Sun Mar 19 11:56:40 AST 2023&lt;/FONT&gt;&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD width="33.333333333333336%" height="30px"&gt;&lt;FONT size="2"&gt;4&lt;/FONT&gt;&lt;/TD&gt;&lt;TD width="33.333333333333336%" height="30px"&gt;&lt;FONT size="2"&gt;ACT+X&lt;/FONT&gt;&lt;/TD&gt;&lt;TD width="33.333333333333336%" height="30px"&gt;&lt;FONT size="2"&gt;Sun Mar 19 11:56:40 AST 2023&lt;/FONT&gt;&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD width="33.333333333333336%" height="30px"&gt;&lt;FONT size="2"&gt;5&lt;/FONT&gt;&lt;/TD&gt;&lt;TD width="33.333333333333336%" height="30px"&gt;&lt;FONT size="2"&gt;ACT+X&lt;/FONT&gt;&lt;/TD&gt;&lt;TD width="33.333333333333336%" height="30px"&gt;&lt;FONT size="2"&gt;Sun Mar 19 11:56:40 AST 2023&lt;/FONT&gt;&lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;</description>
      <pubDate>Sun, 19 Mar 2023 11:22:53 GMT</pubDate>
      <guid>https://community.cloudera.com/t5/Support-Questions/Convert-json-to-multiple-insert-sql-format/m-p/366411#M239575</guid>
      <dc:creator>ahmedalsaidi</dc:creator>
      <dc:date>2023-03-19T11:22:53Z</dc:date>
    </item>
    <item>
      <title>Re: Convert json to multiple insert sql format</title>
      <link>https://community.cloudera.com/t5/Support-Questions/Convert-json-to-multiple-insert-sql-format/m-p/366423#M239576</link>
      <description>&lt;P&gt;Hi ,&lt;/P&gt;&lt;P&gt;My guess is that you are trying to use &lt;STRONG&gt;ConvertJsonToSQL&lt;/STRONG&gt; &amp;amp; &lt;STRONG&gt;PutSQL&lt;/STRONG&gt; to transpose the json into sql table. For this to happen you cant use the input json in the given format , you need to transform it using JoltTransformJSON processor to create an array of records where each record consist of&amp;nbsp; "sbrActivityType" &amp;amp; "sbrDateTime" columns. The json keys have to match the table column names for this to work. The jolt spec to use can look like this:&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;[
  {
    "operation": "shift",
    "spec": {
      "sbrActivityType": {
        // convert every activity into an array element
        "*": "data[#1].sbrActivityType"
      },
      "sbrDateTime": "sbrDateTime"
    }
  },
  {
    "operation": "modify-default-beta", 
    "spec": { 
      "data": {
        "*": {
          // create new sbrDateTime key under each array element from
          // above and set its value to the initial sbrDateTime
          "sbrDateTime": "@(3,sbrDateTime)"
        }
        
      }
    }
  }
]&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;you set the &lt;STRONG&gt;Jolt Specification&lt;/STRONG&gt; property with the spec above in the &lt;STRONG&gt;JoltTransformJSON&amp;nbsp;&lt;/STRONG&gt;&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="SAMSAL_0-1679238106574.png" style="width: 400px;"&gt;&lt;img src="https://community.cloudera.com/t5/image/serverpage/image-id/37022iCF7E3F9E72902FFF/image-size/medium?v=v2&amp;amp;px=400" role="button" title="SAMSAL_0-1679238106574.png" alt="SAMSAL_0-1679238106574.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;This should give you new json flowfile as follows:&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;{
  "data" : [ {
    "sbrActivityType" : "ACT+A",
    "sbrDateTime" : "Sun Mar 19 13:45:15 AST 2023"
  }, {
    "sbrActivityType" : "ACT+X",
    "sbrDateTime" : "Sun Mar 19 13:45:15 AST 2023"
  }, {
    "sbrActivityType" : "ACT+A",
    "sbrDateTime" : "Sun Mar 19 13:45:15 AST 2023"
  }, {
    "sbrActivityType" : "ACT+X",
    "sbrDateTime" : "Sun Mar 19 13:45:15 AST 2023"
  }, {
    "sbrActivityType" : "ACT+X",
    "sbrDateTime" : "Sun Mar 19 13:45:15 AST 2023"
  } ],
  "sbrDateTime" : "Sun Mar 19 13:45:15 AST 2023"
}&lt;/LI-CODE&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;P&gt;After that, use SplitJosn to split each record into its own json flowfile. The split &lt;STRONG&gt;JsonPath Expression&lt;/STRONG&gt; is set to &lt;STRONG&gt;$.data.*:&lt;/STRONG&gt;&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="SAMSAL_3-1679238260659.png" style="width: 400px;"&gt;&lt;img src="https://community.cloudera.com/t5/image/serverpage/image-id/37025iE1B8F73D9BAD226F/image-size/medium?v=v2&amp;amp;px=400" role="button" title="SAMSAL_3-1679238260659.png" alt="SAMSAL_3-1679238260659.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;Then you use &lt;STRONG&gt;ConvertJSONToSQL&lt;/STRONG&gt; as follows:&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="SAMSAL_4-1679238363872.png" style="width: 400px;"&gt;&lt;img src="https://community.cloudera.com/t5/image/serverpage/image-id/37026i71F3813CF8D1616F/image-size/medium?v=v2&amp;amp;px=400" role="button" title="SAMSAL_4-1679238363872.png" alt="SAMSAL_4-1679238363872.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;And Finally you use the &lt;STRONG&gt;PUTSQL&lt;/STRONG&gt; processor as follows:&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="SAMSAL_5-1679238426041.png" style="width: 400px;"&gt;&lt;img src="https://community.cloudera.com/t5/image/serverpage/image-id/37027i96EB2198BB457454/image-size/medium?v=v2&amp;amp;px=400" role="button" title="SAMSAL_5-1679238426041.png" alt="SAMSAL_5-1679238426041.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;This should populate the table accordingly:&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="SAMSAL_6-1679238490140.png" style="width: 400px;"&gt;&lt;img src="https://community.cloudera.com/t5/image/serverpage/image-id/37028i9A7D99C0325D4CDE/image-size/medium?v=v2&amp;amp;px=400" role="button" title="SAMSAL_6-1679238490140.png" alt="SAMSAL_6-1679238490140.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;If this helps please &lt;U&gt;&lt;STRONG&gt;accept&lt;/STRONG&gt; &lt;/U&gt;solution.&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;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sun, 19 Mar 2023 15:14:45 GMT</pubDate>
      <guid>https://community.cloudera.com/t5/Support-Questions/Convert-json-to-multiple-insert-sql-format/m-p/366423#M239576</guid>
      <dc:creator>SAMSAL</dc:creator>
      <dc:date>2023-03-19T15:14:45Z</dc:date>
    </item>
    <item>
      <title>Re: Convert json to multiple insert sql format</title>
      <link>https://community.cloudera.com/t5/Support-Questions/Convert-json-to-multiple-insert-sql-format/m-p/366742#M239669</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;I think the&amp;nbsp;&lt;SPAN&gt;jolt spec is incorrect because one of parentheses are more or less&amp;nbsp;at 5th line.&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;If you can help me on this I appreciate it.&lt;/P&gt;</description>
      <pubDate>Thu, 23 Mar 2023 08:26:29 GMT</pubDate>
      <guid>https://community.cloudera.com/t5/Support-Questions/Convert-json-to-multiple-insert-sql-format/m-p/366742#M239669</guid>
      <dc:creator>ahmedalsaidi</dc:creator>
      <dc:date>2023-03-23T08:26:29Z</dc:date>
    </item>
    <item>
      <title>Re: Convert json to multiple insert sql format</title>
      <link>https://community.cloudera.com/t5/Support-Questions/Convert-json-to-multiple-insert-sql-format/m-p/366773#M239672</link>
      <description>&lt;P&gt;Ignore my statement, it is ok now, but I did not finish the pipeline yet, I will let you know back again once I done&lt;/P&gt;</description>
      <pubDate>Thu, 23 Mar 2023 11:15:02 GMT</pubDate>
      <guid>https://community.cloudera.com/t5/Support-Questions/Convert-json-to-multiple-insert-sql-format/m-p/366773#M239672</guid>
      <dc:creator>ahmedalsaidi</dc:creator>
      <dc:date>2023-03-23T11:15:02Z</dc:date>
    </item>
    <item>
      <title>Re: Convert json to multiple insert sql format</title>
      <link>https://community.cloudera.com/t5/Support-Questions/Convert-json-to-multiple-insert-sql-format/m-p/366774#M239673</link>
      <description>&lt;P&gt;Once I d SplitJson processor, it give so many flow files, how to limit to the number of input flow file. For example, in my example here: we have 5 ACTs (means we have 5 records in the target database table)&lt;/P&gt;</description>
      <pubDate>Thu, 23 Mar 2023 11:38:40 GMT</pubDate>
      <guid>https://community.cloudera.com/t5/Support-Questions/Convert-json-to-multiple-insert-sql-format/m-p/366774#M239673</guid>
      <dc:creator>ahmedalsaidi</dc:creator>
      <dc:date>2023-03-23T11:38:40Z</dc:date>
    </item>
    <item>
      <title>Re: Convert json to multiple insert sql format</title>
      <link>https://community.cloudera.com/t5/Support-Questions/Convert-json-to-multiple-insert-sql-format/m-p/366802#M239677</link>
      <description>&lt;P&gt;What do you mean by it gave you "so many flowfiles". If you follow the same jolt spec and split processors configuration as I provided it should give you the exact amount flowfiles similar to the number of ACT in the original input. Can you provide more details?&lt;/P&gt;</description>
      <pubDate>Thu, 23 Mar 2023 12:58:35 GMT</pubDate>
      <guid>https://community.cloudera.com/t5/Support-Questions/Convert-json-to-multiple-insert-sql-format/m-p/366802#M239677</guid>
      <dc:creator>SAMSAL</dc:creator>
      <dc:date>2023-03-23T12:58:35Z</dc:date>
    </item>
    <item>
      <title>Re: Convert json to multiple insert sql format</title>
      <link>https://community.cloudera.com/t5/Support-Questions/Convert-json-to-multiple-insert-sql-format/m-p/366938#M239718</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://community.cloudera.com/t5/user/viewprofilepage/user-id/80381"&gt;@SAMSAL&lt;/a&gt;&amp;nbsp;, it gives the following number of flow files (forever), although the source flow file as provided in the question around 3 ACT.As and 2 ACT.Xs.&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="ahmedalsaidi_0-1679816694822.png" style="width: 400px;"&gt;&lt;img src="https://community.cloudera.com/t5/image/serverpage/image-id/37089iC44C1BC342360A67/image-size/medium?v=v2&amp;amp;px=400" role="button" title="ahmedalsaidi_0-1679816694822.png" alt="ahmedalsaidi_0-1679816694822.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I hope my explanation was fine and ok.&lt;/P&gt;</description>
      <pubDate>Sun, 26 Mar 2023 07:47:37 GMT</pubDate>
      <guid>https://community.cloudera.com/t5/Support-Questions/Convert-json-to-multiple-insert-sql-format/m-p/366938#M239718</guid>
      <dc:creator>ahmedalsaidi</dc:creator>
      <dc:date>2023-03-26T07:47:37Z</dc:date>
    </item>
    <item>
      <title>Re: Convert json to multiple insert sql format</title>
      <link>https://community.cloudera.com/t5/Support-Questions/Convert-json-to-multiple-insert-sql-format/m-p/366947#M239719</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;I noticed that you have an "Original" relationship going from SplitJson back to itself. This where your duplicates are coming from. The "Original" relationship means the original input flowfile that is passed to the splitJson from JoltTransformation processor. You need to terminate this relationship and not pass it to anything&amp;nbsp; unless you are using Wait-Notify processors which I dont think in your case. You can terminate relationship by going to splitJson Configuration then go to the Relationship tab and check the terminate box under the Original relationship.&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;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sun, 26 Mar 2023 13:12:21 GMT</pubDate>
      <guid>https://community.cloudera.com/t5/Support-Questions/Convert-json-to-multiple-insert-sql-format/m-p/366947#M239719</guid>
      <dc:creator>SAMSAL</dc:creator>
      <dc:date>2023-03-26T13:12:21Z</dc:date>
    </item>
    <item>
      <title>Re: Convert json to multiple insert sql format</title>
      <link>https://community.cloudera.com/t5/Support-Questions/Convert-json-to-multiple-insert-sql-format/m-p/366977#M239737</link>
      <description>&lt;P&gt;Thanks&amp;nbsp;&lt;a href="https://community.cloudera.com/t5/user/viewprofilepage/user-id/80381"&gt;@SAMSAL&lt;/a&gt;&amp;nbsp;, everything it works fine....&lt;/P&gt;</description>
      <pubDate>Mon, 27 Mar 2023 10:13:25 GMT</pubDate>
      <guid>https://community.cloudera.com/t5/Support-Questions/Convert-json-to-multiple-insert-sql-format/m-p/366977#M239737</guid>
      <dc:creator>ahmedalsaidi</dc:creator>
      <dc:date>2023-03-27T10:13:25Z</dc:date>
    </item>
  </channel>
</rss>

