<?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 array to SQL database in Support Questions</title>
    <link>https://community.cloudera.com/t5/Support-Questions/Convert-JSON-array-to-SQL-database/m-p/363200#M238931</link>
    <description>&lt;P&gt;Thank you very much!!&lt;/P&gt;</description>
    <pubDate>Mon, 06 Feb 2023 14:42:25 GMT</pubDate>
    <dc:creator>YueikO</dc:creator>
    <dc:date>2023-02-06T14:42:25Z</dc:date>
    <item>
      <title>Convert JSON array to SQL database</title>
      <link>https://community.cloudera.com/t5/Support-Questions/Convert-JSON-array-to-SQL-database/m-p/363058#M238904</link>
      <description>&lt;P&gt;Hi all,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I'm very new to NiFi and trying to find ways how to convert json array to be stored in SQL database. I currently have this input json&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;{
  "QueryHandle" : "#qb9ec959946924620a6f46013d745fe03",
  "Rows" : [ {
    "Values" : [ "A1", "Test Data A1" ]
  }, {
    "Values" : [ "A2", "Test Data A2" ]
  }, {
    "Values" : [ "A3", "Test Data A3" ]
  }, {
    "Values" : [ "A4", "Test Data A4" ]
  } ],
  "TotalRowCount" : 197,
  "DataTypes" : {
    "Values" : [ {
      "ColumnName" : "Value",
      "Type" : "String"
    }, {
      "ColumnName" : "Description",
      "Type" : "String"
    } ]
  }
}&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Here's the end result I would like to have before I can use PutSQL processor&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;[ {
  "VALUES" : "A1",
  "DESCRIPTION" : "Test Data A1"
}, {
  "VALUES" : "A2",
  "DESCRIPTION" : "Test Data A2"
}, {
  "VALUES" : "A3",
  "DESCRIPTION" : "Test Data A3",
}, {
  "VALUES" : "A4",
  "DESCRIPTION" : "Test Data A4",
}&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I have tried to use jolttransform, but couldn't be able to remove the array or to add the field name to the data. Eventually, I would like to see this in my DB&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;TABLE border="1" width="37.40678267045454%"&gt;&lt;TBODY&gt;&lt;TR&gt;&lt;TD width="13.128678601457977%"&gt;VALUE&lt;/TD&gt;&lt;TD width="25.520746685898345%"&gt;DESCRIPTION&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD width="13.128678601457977%"&gt;A1&lt;/TD&gt;&lt;TD width="25.520746685898345%"&gt;Test Data A1&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD width="13.128678601457977%"&gt;A2&lt;/TD&gt;&lt;TD width="25.520746685898345%"&gt;Test Data A2&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD width="13.128678601457977%"&gt;A3&lt;/TD&gt;&lt;TD width="25.520746685898345%"&gt;Test Data A3&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD width="13.128678601457977%"&gt;A4&lt;/TD&gt;&lt;TD width="25.520746685898345%"&gt;Test Data A4&lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thank you in advance.&lt;/P&gt;</description>
      <pubDate>Fri, 03 Feb 2023 14:29:33 GMT</pubDate>
      <guid>https://community.cloudera.com/t5/Support-Questions/Convert-JSON-array-to-SQL-database/m-p/363058#M238904</guid>
      <dc:creator>YueikO</dc:creator>
      <dc:date>2023-02-03T14:29:33Z</dc:date>
    </item>
    <item>
      <title>Re: Convert JSON array to SQL database</title>
      <link>https://community.cloudera.com/t5/Support-Questions/Convert-JSON-array-to-SQL-database/m-p/363067#M238906</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;I think this can be achieved using the following flow:&lt;/P&gt;&lt;P&gt;(Data Source) -&amp;gt; SplitJson -&amp;gt;JoltTransformationJSON -&amp;gt;ConcertJSONToSQL-&amp;gt;PutSQL&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;The Configuration for each processor is as follows:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;1- &lt;STRONG&gt;SplitJson&lt;/STRONG&gt; (To get Each of the Rows Element as flowfile)&lt;/P&gt;&lt;P&gt;JsonPath Expression = $.Rows&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="SAMSAL_0-1675442122040.png" style="width: 400px;"&gt;&lt;img src="https://community.cloudera.com/t5/image/serverpage/image-id/36717i575479A7C6FEEA38/image-size/medium?v=v2&amp;amp;px=400" role="button" title="SAMSAL_0-1675442122040.png" alt="SAMSAL_0-1675442122040.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;2-&lt;STRONG&gt;JoltTransformationJSON&lt;/STRONG&gt; (Convert Each Row Values Element to proper format):&lt;/P&gt;&lt;P&gt;Example Input: { "Values": [ "A4", "Test Data A4"] }&lt;/P&gt;&lt;P&gt;Output: { "VALUE" : "A4", "DESCRIPTION" : "Test Data A4" }&lt;BR /&gt;Jolt Spec:&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;[
  {
    "operation": "shift",
    "spec": {
      "Values": {
        "0": "VALUE",
        "1": "DESCRIPTION"
      }
    }
  }
]&lt;/LI-CODE&gt;&lt;P&gt;&lt;U&gt;&lt;STRONG&gt;Note:&lt;/STRONG&gt;&lt;/U&gt; The Output Json Keys has to match the column name in the SQL table&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;3- ConverJSONToSQL ( This is to convert the jolt output json to sql statement that will feed into the PutSql&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="SAMSAL_1-1675442622650.png" style="width: 400px;"&gt;&lt;img src="https://community.cloudera.com/t5/image/serverpage/image-id/36718i493BCCA9A0B3C69D/image-size/medium?v=v2&amp;amp;px=400" role="button" title="SAMSAL_1-1675442622650.png" alt="SAMSAL_1-1675442622650.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;Note: you need to Populate the JDBC Connection Pool&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;4- PutSql (used to execute the insert sql statement generated from above into the DB Table.&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="SAMSAL_2-1675442714031.png" style="width: 400px;"&gt;&lt;img src="https://community.cloudera.com/t5/image/serverpage/image-id/36719i27F388C490B2A4A7/image-size/medium?v=v2&amp;amp;px=400" role="button" title="SAMSAL_2-1675442714031.png" alt="SAMSAL_2-1675442714031.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;Note: You need to create the &lt;STRONG&gt;JDBC Connection Pool&lt;/STRONG&gt;. &lt;STRONG&gt;SQL Statement Property&lt;/STRONG&gt; remains empty to use the SQL statement from the flowfile generated in step 3.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;If that helps &lt;STRONG&gt;please accept solution.&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;Thanks&lt;/STRONG&gt;&lt;/P&gt;</description>
      <pubDate>Fri, 03 Feb 2023 16:48:08 GMT</pubDate>
      <guid>https://community.cloudera.com/t5/Support-Questions/Convert-JSON-array-to-SQL-database/m-p/363067#M238906</guid>
      <dc:creator>SAMSAL</dc:creator>
      <dc:date>2023-02-03T16:48:08Z</dc:date>
    </item>
    <item>
      <title>Re: Convert JSON array to SQL database</title>
      <link>https://community.cloudera.com/t5/Support-Questions/Convert-JSON-array-to-SQL-database/m-p/363200#M238931</link>
      <description>&lt;P&gt;Thank you very much!!&lt;/P&gt;</description>
      <pubDate>Mon, 06 Feb 2023 14:42:25 GMT</pubDate>
      <guid>https://community.cloudera.com/t5/Support-Questions/Convert-JSON-array-to-SQL-database/m-p/363200#M238931</guid>
      <dc:creator>YueikO</dc:creator>
      <dc:date>2023-02-06T14:42:25Z</dc:date>
    </item>
  </channel>
</rss>

