<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>SSIS Export JSON Task Archives | ZappySys Blog</title>
	<atom:link href="https://zappysys.com/blog/tag/ssis-export-json-task/feed/" rel="self" type="application/rss+xml" />
	<link>https://zappysys.com/blog/tag/ssis-export-json-task/</link>
	<description>SSIS / ODBC Drivers / API Connectors for JSON, XML, Azure, Amazon AWS, Salesforce, MongoDB and more</description>
	<lastBuildDate>Sun, 08 Jan 2023 21:06:29 +0000</lastBuildDate>
	<language>en-US</language>
	<sy:updatePeriod>
	hourly	</sy:updatePeriod>
	<sy:updateFrequency>
	1	</sy:updateFrequency>
	<generator>https://wordpress.org/?v=6.4.4</generator>

<image>
	<url>https://zappysys.com/blog/wp-content/uploads/2023/01/cropped-zappysys-symbol-large-32x32.png</url>
	<title>SSIS Export JSON Task Archives | ZappySys Blog</title>
	<link>https://zappysys.com/blog/tag/ssis-export-json-task/</link>
	<width>32</width>
	<height>32</height>
</image> 
	<item>
		<title>SSIS &#8211; Loading data into MongoDB (Upsert, Delete, Update)</title>
		<link>https://zappysys.com/blog/ssis-loading-data-into-mongodb-upsert-update-delete-insert/</link>
		
		<dc:creator><![CDATA[ZappySys]]></dc:creator>
		<pubDate>Fri, 26 Feb 2016 22:03:21 +0000</pubDate>
				<category><![CDATA[SSIS MongoDB Destination]]></category>
		<category><![CDATA[export json task]]></category>
		<category><![CDATA[json]]></category>
		<category><![CDATA[MongoDB]]></category>
		<category><![CDATA[nosql]]></category>
		<category><![CDATA[ssis]]></category>
		<category><![CDATA[ssis connectors]]></category>
		<category><![CDATA[SSIS Dummy Data Source]]></category>
		<category><![CDATA[SSIS Export JSON Task]]></category>
		<category><![CDATA[SSIS JSON Generator Transform]]></category>
		<category><![CDATA[SSIS MongoDB ExecuteSQL Task]]></category>
		<category><![CDATA[SSIS MongoDB Source]]></category>
		<category><![CDATA[ssis tasks]]></category>
		<category><![CDATA[upsert]]></category>
		<guid isPermaLink="false">http://zappysys.com/blog/?p=374</guid>

					<description><![CDATA[<p>Introduction MongoDB is one of the most poplar NoSQL database out there. In this article you will learn how to use ZappySys MongoDB Destination Connector to perform various bulk operations on MongoDB such as Insert, Update, Delete and Upsert. If you wish to learn how to Update MongoDB Array items then check this blog post instread. [&#8230;]</p>
<p>The post <a href="https://zappysys.com/blog/ssis-loading-data-into-mongodb-upsert-update-delete-insert/">SSIS &#8211; Loading data into MongoDB (Upsert, Delete, Update)</a> appeared first on <a href="https://zappysys.com/blog">ZappySys Blog</a>.</p>
]]></description>
										<content:encoded><![CDATA[<h2>Introduction</h2>
<p><img decoding="async" class="size-full wp-image-2115 alignleft" src="https://zappysys.com/blog/wp-content/uploads/2017/08/mongodb-logo.png" alt="" width="88" height="88" />MongoDB is one of the most poplar <strong>NoSQL database</strong> out there. In this article you will learn how to use <a href="//zappysys.com/products/ssis-powerpack/ssis-mongodb-destination/">ZappySys MongoDB Destination Connector</a> to perform various bulk operations on MongoDB such as Insert, Update, Delete and Upsert. If you wish to learn <a href="//zappysys.com/blog/update-mongodb-array-items-using-ssis/" target="_blank" rel="noopener">how to Update MongoDB Array items then check this blog post instread</a>.</p>
<p>&nbsp;</p>
<h2>MongoDB data read/write Example SSIS Package</h2>
<p>Before we talk more about loading data into MongoDB lets look at screenshot and steps involved in our sample package for this tutorial. Below sample SSIS package uses 4 <strong>Custom SSIS Tasks</strong></p>
<ol>
<li><a href="//zappysys.com/products/ssis-powerpack/ssis-mongodb-source/">SSIS MongoDB Source Connector</a> (Used to read data from MongoDB Collection)</li>
<li><a href="//zappysys.com/products/ssis-powerpack/ssis-mongodb-destination/">SSIS MongoDB Destination Connector</a> (Used to write data into MongoDB Collection also you can do other bulk operations such as MongoDB update, MongoDB upsert and MongoDB delete)</li>
<li><a href="//zappysys.com/products/ssis-powerpack/ssis-mongodb-executesql-task/">SSIS MongoDB ExecuteSQL Task</a> (Used to call any MongoDB Shell commands including MongoDB DDL or DML type operations such as CREATE/DROP, Insert, Update, Delete, Read, you can also call server side JavaScript)</li>
<li><a href="//zappysys.com/products/ssis-powerpack/dummy-data-source-free/">Dummy Data Source</a> (Used to generate sample JSON Documents which can be loaded in MongoDB)</li>
</ol>
<h2>MongoDB Examples</h2>
<p>Here is the list of various MongoDB examples included in attached sample package (see at the end for download links)</p>
<ul>
<li>MongoDB example &#8211; How to <em>read data from MongoDB</em> collection using SQL query language</li>
<li>MongoDB example &#8211; How to <em>load raw JSON document</em> into MongoDB Collection (<strong>Bulk Insert with Reload</strong>)</li>
<li>MongoDB example &#8211; How to do <em>MongoDB Upsert</em> (<strong>Bulk Update</strong> or Insert) for specific fields or entire document</li>
<li>MongoDB example &#8211; How to perform MongoDB Delete ( <strong>Bulk Delete</strong> based on Matching Rows)</li>
<li>MongoDB example &#8211; How to <strong>create new MongoDB collection</strong> (Only if not exist &#8211; Use safe option)</li>
<li>MongoDB example &#8211; How to fetch MongoDB collection <strong>record count</strong> and save to SSIS variable</li>
<li>MongoDB example &#8211; How to fetch MongoDB <strong>collection size</strong> and save to SSIS variable</li>
<li>MongoDB example &#8211; How to <strong>get collection names</strong> and loop through them using ForEach Loop Task</li>
<li>MongoDB example &#8211; How to <strong>save query output</strong> into Recordset variable and loop though records using ForEach Loop Task</li>
</ul>
<h2>Video Tutorial &#8211; Update/Delete/Write/Bulk Load data into MongoDB from SQL Server/ORACLE</h2>
<p>In below video tutorial you will see how easy it is to load data into MongoDB from any Datasource such as SQL Server, Oracle, MySQL, Flatfile etc. You will also learn how to product nested JSON from multiple tables using <a href="//zappysys.com/products/ssis-powerpack/ssis-json-generator-transform/" target="_blank" rel="noopener">JSON Generator Transform</a>. You can also use <a href="//zappysys.com/products/ssis-powerpack/ssis-json-file-source/" target="_blank" rel="noopener">JSON Source</a> with Output as Document Mode to load raw JSON data.</p>
<div><a href="https://zappysys.com/blog/ssis-loading-data-into-mongodb-upsert-update-delete-insert/"><img decoding="async" src="https://zappysys.com/blog/wp-content/plugins/wp-youtube-lyte/lyteCache.php?origThumbUrl=%2F%2Fi.ytimg.com%2Fvi%2FFkQjUahzMJQ%2Fhqdefault.jpg" alt="YouTube Video"></a><br /><br /></div>
<h2>Video Tutorial &#8211; Read data from MongoDB</h2>
<p>In the following video tutorial you will learn how to consume data from MongoDB Collection using <a href="//zappysys.com/products/ssis-powerpack/ssis-mongodb-source/" target="_blank" rel="noopener">SSIS MongoDB Source Connector</a>. You will notice that it uses <strong>SQL query syntax</strong> rather than MongoDB specific native query syntax (JSON query). This makes it super easy to query data without any learning curve. Data stored in MongoDB is in JSON document format but Data coming out from <strong>MongoDB Source Connector</strong> is Flat table structure (It de-normalize nested nodes). You can also Query inner Hierarchy using <strong>JSON Path expression</strong> (e.g. query Orders from Customer Document using <strong>$.Customer.Orders[*]</strong> ) .</p>
<div><a href="https://zappysys.com/blog/ssis-loading-data-into-mongodb-upsert-update-delete-insert/"><img decoding="async" src="https://zappysys.com/blog/wp-content/plugins/wp-youtube-lyte/lyteCache.php?origThumbUrl=%2F%2Fi.ytimg.com%2Fvi%2FksvCA8FxOzI%2Fhqdefault.jpg" alt="YouTube Video"></a><br /><br /></div>
<div id="attachment_388" style="width: 362px" class="wp-caption alignnone"><a href="//zappysys.com/blog/wp-content/uploads/2016/02/ssis-loading-data-into-mongodb-read-from-mongodb-upsert-delete-insert-example.png"><img fetchpriority="high" decoding="async" aria-describedby="caption-attachment-388" class="size-full wp-image-388" src="//zappysys.com/blog/wp-content/uploads/2016/02/ssis-loading-data-into-mongodb-read-from-mongodb-upsert-delete-insert-example.png" alt="SSIS Example - Loading data into MongoDB, Read from MongoDB, Upsert, Upsert, Delete Insert JSON Documents, Execute Shell Commands" width="352" height="482" srcset="https://zappysys.com/blog/wp-content/uploads/2016/02/ssis-loading-data-into-mongodb-read-from-mongodb-upsert-delete-insert-example.png 352w, https://zappysys.com/blog/wp-content/uploads/2016/02/ssis-loading-data-into-mongodb-read-from-mongodb-upsert-delete-insert-example-219x300.png 219w" sizes="(max-width: 352px) 100vw, 352px" /></a><p id="caption-attachment-388" class="wp-caption-text">SSIS Example &#8211; Loading data into MongoDB, Read from MongoDB, Upsert, Upsert, Delete Insert JSON Documents, Execute Shell Commands</p></div>
<h2>MongoDB Insert &#8211; Bulk Loading data into MongoDB</h2>
<p>Using MongoDB Destination Connector you can easily Insert JSON documents in Bulk. There are two input modes for inserting records into MongoDB.</p>
<h3>Simple Mode &#8211; Loading data in simple mode (array not allowed)</h3>
<p>In simple loading mode you can map source columns to target column in MongoDB destination. If you Insert data using this mode then you cant load complex documents with array.</p>
<h3>Document Mode &#8211; Loading JSON documents into MongoDB</h3>
<p>In this mode you can insert/update/delete documents by mapping inbuilt __DOCUMENT__ input column which appears on mapping tab (Target columns). When you perform Insert you have two options (Insert (i.e. Append) and Reload (Truncate + Insert). When you select Operation=Reload in that case Collection is first Truncated and then new records are loaded.</p>
<p>In JSON document load mode if you don&#8217;t supply _id column part of your input JSON then new _id is automatically generated by MongoDB for newly inserted document.</p>
<div id="attachment_392" style="width: 589px" class="wp-caption alignnone"><a href="//zappysys.com/blog/wp-content/uploads/2016/02/ssis-load-json-documents-into-mongodb-collection.png"><img loading="lazy" decoding="async" aria-describedby="caption-attachment-392" class="size-full wp-image-392" src="//zappysys.com/blog/wp-content/uploads/2016/02/ssis-load-json-documents-into-mongodb-collection.png" alt="Loading JSON Documents into MongoDB Collection (Map Raw Document Column)" width="579" height="669" srcset="https://zappysys.com/blog/wp-content/uploads/2016/02/ssis-load-json-documents-into-mongodb-collection.png 579w, https://zappysys.com/blog/wp-content/uploads/2016/02/ssis-load-json-documents-into-mongodb-collection-260x300.png 260w" sizes="(max-width: 579px) 100vw, 579px" /></a><p id="caption-attachment-392" class="wp-caption-text">Loading JSON Documents into MongoDB Collection (Map Raw Document Column)</p></div>
<h3>Loading JSON files into MongoDB</h3>
<p>Another scenario could be loading JSON files into MongoDB. You can load JSON Files into MongoDB two ways.</p>
<ul>
<li>Use Flat File Source with just one column with DT_NTEXT datatype (use this method when you each JSON documents in one line and they are separated by new line as below screenshot)</li>
<li>Use <a href="//zappysys.com/products/ssis-powerpack/ssis-json-file-source/">JSON Source Connector</a> with Output as Document option checked. You can map __DOCUMENT__ source column to Target MongoDB collection as below. Advantage of this method is you extract JSON from array too and specify many other advanced options.
<div id="attachment_393" style="width: 733px" class="wp-caption alignnone"><a href="//zappysys.com/blog/wp-content/uploads/2016/02/ssis-extract-raw-json-documents-from-json-file.png"><img loading="lazy" decoding="async" aria-describedby="caption-attachment-393" class="size-full wp-image-393" src="//zappysys.com/blog/wp-content/uploads/2016/02/ssis-extract-raw-json-documents-from-json-file.png" alt="SSIS Extract JSON Documents or Sub Documents from JSON file or JSON Array" width="723" height="605" srcset="https://zappysys.com/blog/wp-content/uploads/2016/02/ssis-extract-raw-json-documents-from-json-file.png 723w, https://zappysys.com/blog/wp-content/uploads/2016/02/ssis-extract-raw-json-documents-from-json-file-300x251.png 300w" sizes="(max-width: 723px) 100vw, 723px" /></a><p id="caption-attachment-393" class="wp-caption-text">SSIS Extract JSON Documents or Sub Documents from JSON file or JSON Array</p></div></li>
</ul>
<h2>Specifying LoadOptions</h2>
<p><a href="//zappysys.com/products/ssis-powerpack/ssis-mongodb-destination/">MongoDB Destination Connector</a> supports following <strong>LoadOptions</strong> property (see Component Properties Tab on UI) which controls how target data gets modified. <strong>LoadOptions</strong> property is ignored for <strong>Reload</strong> and <strong>Insert</strong> operations.</p>
<ul>
<li><strong>op</strong> : this option specify update operators (Valid for <strong>Update, Replace</strong> and <strong>Upsert</strong> operation (i.e. <strong>UpdateOrInsert</strong>) ).  See <a href="https://docs.mongodb.org/manual/reference/operator/update/" target="_blank" rel="noopener">this link</a> for more information on various Update operators available in MongoDB. Most common operators listed below. Refer official MongoDB <a href="https://docs.mongodb.org/manual/reference/operator/update/" target="_blank" rel="noopener">help</a> for more information.
<ul>
<li><strong>op=none</strong> : Replace entire document</li>
<li><strong>op=$set</strong>  : Update only those fields specified in mapping. If Specified mapping field not available in target then its added to target document.</li>
<li><strong>op=$push</strong> : Adds new item to destination array. See following examples (How to insert single or multiple documents into MongoDB Array by supplying JSON into  __DOCUMENT__ column<br />
<pre class="crayon-plain-tag">/* Insert single item into array - Construct input JSON as below */
{YourArrayField : 111 }

/* Insert multiple items into array - Construct document as below */
{YourArrayField : { $each: [ 111, 222, 333 ] } }

/* Insert multiple documents into array */
{YourArrayField : { $each: [ {OrderID:1, Total:20.00}, {OrderID:2, Total:12.00} ] } }</pre>
</li>
</ul>
</li>
<li><strong>multi</strong> : This option controls if you want to Update or Delete multiple records for matching condition for each upstream input record.  For example if you joining by Country and City columns for update and target system finds 5 records then by default they all will be updated if <strong>multi=true</strong> is set in <strong>LoadOptions</strong> property. If you don&#8217;t want to update multiple records</li>
</ul>
<h2>MongoDB Update</h2>
<p>MongoDB Destination Connector supports Batch Update and Batch Upsert Operations. There are few things to remember how Update operation works with MongoDB Destination Connector.</p>
<ul>
<li>To perform Update operation you have to specify Join Criteria for record lookup on target (see <strong>ColumnsForLookup</strong> property).</li>
<li>Specify JOIN columns in <strong>ColumnsForLookup</strong> property. Use comma to specify multiple columns (e.g. CustomerID,OrderID). If you dont specify columns in this property then any columns mapped other than __DOCUMENT__ will be considered as JOIN column.</li>
<li>With MongoDB destination you can only specify simple Update condition by mapping JOIN input columns. Behind the scene it will construct search query for update. For example if you Map 3 input columns (__DOCUMENT__ , Country, State) and you specify <strong>LoadOptions :</strong> <strong>op=$set;multi=true</strong> then its similar as below SQL Statement.<br />
<pre class="crayon-plain-tag">UPDATE MyCollection
SET [properties specified in __DOCUMENT__]
WHERE Country=[input value] AND State=[input value]</pre>
</li>
<li>Join columns can be individually mapped or can be supplied as part of JSON document mapped to __DOCUMENT__ column.</li>
<li>If __DOCUMENT__ column is not mapped then you must specify at least one column name in ColumnsForLookup property to identify search column.</li>
<li>If __DOCUMENT__ column is mapped and column name is not specified in <strong>ColumnsForLookup</strong> property then you must map at least one more input column which can treated as JOIN column</li>
</ul>
<h2>Update specific fields  ($set operator)</h2>
<p>To update specific fields in target MongoDB collection you can map JOIN column(s) and then map fields you want to update or map __DOCUMENT__ if you suppling JSON document with fields you want to update.</p>
<p>See below screenshot where its updating Customers record with new coordinates  based on City and Country information.</p>
<div id="attachment_397" style="width: 758px" class="wp-caption alignnone"><a href="//zappysys.com/blog/wp-content/uploads/2016/02/ssis-mongodb-update-json-document-specified-fields-set-operator.png"><img loading="lazy" decoding="async" aria-describedby="caption-attachment-397" class="size-full wp-image-397" src="//zappysys.com/blog/wp-content/uploads/2016/02/ssis-mongodb-update-json-document-specified-fields-set-operator.png" alt="SSIS MongoDB Update Bulk - $set update operator - Update specific fields - Update single or multiple documents" width="748" height="527" srcset="https://zappysys.com/blog/wp-content/uploads/2016/02/ssis-mongodb-update-json-document-specified-fields-set-operator.png 748w, https://zappysys.com/blog/wp-content/uploads/2016/02/ssis-mongodb-update-json-document-specified-fields-set-operator-300x211.png 300w" sizes="(max-width: 748px) 100vw, 748px" /></a><p id="caption-attachment-397" class="wp-caption-text">SSIS MongoDB Update Bulk &#8211; $set update operator &#8211; Update specific fields &#8211; Update single or multiple documents</p></div>
<h3>Update single or multiple target records for single input row</h3>
<p>If you want to update all matching records in target then set <strong>LoadOptions</strong> property to <strong>op=$set,multi=true</strong><br />
If you want to update only one record per matching criteria in target then set <strong>LoadOptions</strong> property to <strong>op=$set,multi=false</strong></p>
<h3>Update entire document (i.e. Overwrite/Replace documents)</h3>
<p>If you like to replace entire target document then you can do two ways. Few things you have to change for MongoDB Destination.</p>
<p><strong>Approach#1 </strong></p>
<ol>
<li>Select <strong>Operation</strong>=Replace (Rather than Update or Upsert)</li>
<li>Specify Join column in <strong>ColumnsForLookup</strong></li>
<li>On the mapping tab Map __DOCUMENT__ (Assuming you have Raw JSON coming from Upstream)</li>
</ol>
<p><strong>Approach#2</strong></p>
<p>Another approach is use $set operator in LoadOptions property then it will only update specified fields in mappings. But if you want to overwrite entire document (Replace document) then set <strong>LoadOptions</strong> property to <strong>op=none,multi=true</strong> or <strong>op=none,multi=false</strong> (If you want to update one record for matching condition)</p>
<h3>Insert single item into MongoDB Array using $push operator</h3>
<p>If you want to insert new items into array then set <strong>LoadOptions</strong> property to <strong>op=$push,multi=true</strong> or <strong>op=$push,multi=false</strong> (If you want to update one record for matching condition). You have to map __DOCUMENT__ column on target mappings tab to supply item(s) or document(s) you want to insert into target array.</p><pre class="crayon-plain-tag">/* Insert single number or string into MongoDB array - Construct input JSON as below */
{YourArrayField : 111 }

/* Insert single document into MongoDB array - Construct input JSON as below */
{YourArrayField : {OrderID:1, Total:20.00} }</pre><p>
<h3>Insert multiple items into MongoDB Array using $push operator along with $each</h3>
<p>Inserting multiple items into array requires use of <strong>$each</strong> modifier as below. Use above instructions except input document (e.g. data passed to __DOCUMENT__ column) will look like below (see how $each used).</p><pre class="crayon-plain-tag">/* Insert multiple items into MongoDB array - Construct document as below */
{YourArrayField : { $each: [ 111, 222, 333 ] } }

/* Insert multiple documents into MongoDB array */
{YourArrayField : { $each: [ {OrderID:1, Total:20.00}, {OrderID:2, Total:12.00} ] } }</pre><p>
<h3>Other MongoDB Update Operators</h3>
<p>So far we have seen <strong>$set</strong> and <strong>$push</strong> update operators. To learn more about other operators see <a href="https://docs.mongodb.org/manual/reference/operator/update/" target="_blank" rel="noopener">this link</a></p>
<h2>MongoDB Update Array Items ($pull, $push, $addToSet)</h2>
<p>If you wish to update items found inside nested array of document then <a href="//zappysys.com/blog/update-mongodb-array-items-using-ssis/" target="_blank" rel="noopener">Check this full length article</a></p>
<h2>MongoDB Upsert &#8211; Bulk Update or Insert JSON documents</h2>
<p>If you wish to perform Bulk Upsert using MongoDB Destination connector then select Upsert Action from dropdown (Action=UpdateOrInsert). In Upset if document is not found for matching criteria then new document is inserted in MongoDB Collection. If document is found then Update operation occurs. To set specific fields use <strong>op=$set</strong> in LoadOptions   and if you wish to overwrite entire document then use <strong>$op=none</strong> in <strong>LoadOptions </strong></p>
<div id="attachment_400" style="width: 488px" class="wp-caption alignnone"><a href="//zappysys.com/blog/wp-content/uploads/2016/02/ssis-mongodb-upsert-json-document-update-or-insert-bulk.png"><img loading="lazy" decoding="async" aria-describedby="caption-attachment-400" class="size-full wp-image-400" src="//zappysys.com/blog/wp-content/uploads/2016/02/ssis-mongodb-upsert-json-document-update-or-insert-bulk.png" alt="SSIS MongoDB Upsert - Bulk Update or Insert JSON documents" width="478" height="605" srcset="https://zappysys.com/blog/wp-content/uploads/2016/02/ssis-mongodb-upsert-json-document-update-or-insert-bulk.png 478w, https://zappysys.com/blog/wp-content/uploads/2016/02/ssis-mongodb-upsert-json-document-update-or-insert-bulk-237x300.png 237w" sizes="(max-width: 478px) 100vw, 478px" /></a><p id="caption-attachment-400" class="wp-caption-text">SSIS MongoDB Upsert &#8211; Bulk Update or Insert JSON documents</p></div>
<h2>MongoDB Delete &#8211; Bulk delete MongoDB JSON documents</h2>
<p>To delete documents from collection you can set operation=Delete on Component properties page. For delete you can simply map _id column on target or just supply columns based on you want to search records you want to delete.</p>
<p>To delete maximum one record for each input row set <strong>LoadOptions</strong> property to <strong>op=none,multi=false</strong> or set <strong>op=none,multi=false</strong> if you want to delete more than one record for matching condition.</p>
<h2>MongoDB Collection Reload &#8211; Remove All (Truncate collection)</h2>
<p>To reload collection set operation to Reload on Component properties page. <strong>Reload</strong> operation first clears target collection and perform <strong>bulk Insert</strong> operation</p>
<h2>Generate JSON for MongoDB data load</h2>
<p>Now lets talk about different ways to produce simple or complex JSON using ZappySys components.  There are 3 ways you can produce JSON which can be loaded into MongoDB Collection. Following section will describe each approach and you can select which one best suited for you.</p>
<h3>Generate JSON &#8211; Using Export JSON Task</h3>
<p>Export JSON Task can export JSON to File or variable which you can consume via <a href="//zappysys.com/products/ssis-powerpack/ssis-json-file-source/">JSON Source Connector</a> (Check Output as Document option) and supply to MongoDB Destination Connector (map to __DOCUMEN__).</p>
<p>Check this link for more info :  <a href="//zappysys.com/blog/export-json-from-sql-server-using-ssis/" target="_blank" rel="noopener">Export Json from sql server using ssis</a></p>
<h3>Generate JSON &#8211; Using JSON Generator Transform</h3>
<p>JSON generator transform is useful when you want to Produce JSON inside pipeline from single or multiple input.</p>
<p>Check this link for more info :  <a href="https://zappysys.com/products/ssis-powerpack/ssis-json-generator-transform/" target="_blank" rel="noopener">JSON generator Transform (Watch Video on this page)</a></p>
<div style="width: 600px" class="wp-caption alignnone"><img decoding="async" title="JSON Generator Transform - Generate JSON and Load into MongoDB" src="//zappysys.com/onlinehelp/ssis-powerpack/scr/images/json-generator-transform/ssis-json-generator-load-documents-mongodb.png" alt="JSON Generator Transform - Test JSON Path Settings" width="590" /><p class="wp-caption-text">JSON Generator Transform &#8211; Generate JSON documents and load into MongoDB</p></div>
<h3>Generate JSON &#8211; Using Dummy Data Source (Fake JSON for Testing)</h3>
<p>If you need to produce JSON for testing purpose then use <a href="//zappysys.com/products/ssis-powerpack/dummy-data-source-free/" target="_blank" rel="noopener">Dummy Data Source</a> (Select JsonDocuments Template from dropdown and click ok)</p>
<h2>Query/Read data from MongoDB</h2>
<p>Visit following links to learn more about reading data from MongoDB.</p>
<p><a href="//zappysys.com/products/ssis-powerpack/ssis-mongodb-source/">SSIS MongoDB Source Homepage</a><br />
<a href="//zappysys.com/onlinehelp/ssis-powerpack/scr/mongodb-source.htm#A_QueryLanguage">MongoDB SQL Query Reference</a><br />
<a href="//zappysys.com/blog/read-mongodb-data-from-array-extract-nested-sub-documents/">MongoDB data extract &#8211; from nested sub documents and array</a></p>
<h2>Execute MongoDB Shell commands in SSIS (e.g. Create/Drop collection)</h2>
<p>MongoDB SOurce and Destination Connectors are great for read/write data. But what if you want to issue ad-hoc MongoDB shell command such as create collection/drop collection ? No worry.. <a href="//zappysys.com/products/ssis-powerpack/">SSIS PowerPack v2.0</a> released new Task called <a href="//zappysys.com/products/ssis-powerpack/ssis-mongodb-executesql-task/">SSIS MongoDB ExecuteSQL Task</a> This task comes with many examples listed on the UI itself (Look for Examples dropdown menu on UI). You can use <a href="//zappysys.com/products/ssis-powerpack/ssis-mongodb-executesql-task/">SSIS MongoDB ExecuteSQL Task</a> to perform many operations such as</p>
<ul>
<li>Create/Drop MongoDB collections</li>
<li>Get collection list as ADO.net recordset so you can loop through using ForEachLoop task</li>
<li>Call serverside JavaScript</li>
<li>Fetch data as ADO.net recordset and store in SSIS variable so you can loop using ForEachLoop task</li>
<li>Drop database</li>
<li>Call many shell commands</li>
</ul>
<h2>Download MongoDB Example Files used in this tutorial</h2>
<p>To test this package you first need to <a href="//zappysys.com/products/ssis-powerpack/">download SSIS PowerPack</a><br />
Once SSIS PowerPack installed you can download following SSIS sample project file(s).</p>
<p><a title="MongoDB Examples - Loading data into MongoDB - SSIS 2008" href="//zappysys.com/downloads/files/ssis/MongoDB_Load_Demo_2008.zip">Download sample files &#8211; SSIS 2008</a><br />
<a title="MongoDB Examples - Loading data into MongoDB - SSIS 2012" href="//zappysys.com/downloads/files/ssis/MongoDB_Load_Demo_2012.zip">Download sample files &#8211; SSIS 2012</a><br />
<a title="MongoDB Examples - Loading data into MongoDB - SSIS 2014" href="//zappysys.com/downloads/files/ssis/MongoDB_Load_Demo_2014.zip">Download sample files &#8211; SSIS 2014</a><br />
<a title="MongoDB Examples - Loading data into MongoDB - SSIS 2016" href="//zappysys.com/downloads/files/ssis/MongoDB_Load_Demo_2016.zip">Download sample files &#8211; SSIS 2016</a></p>
<h2>Conclusion</h2>
<p>MongoDB makes it super easy to store <strong>JSON documents</strong> and gives you whole new way of manipulating documents with ease of use. ZappySys SSIS Connectors and Tasks for MongoDB makes it possible to implement various data integration scenarios with MongoDB. <a href="//zappysys.com/products/ssis-powerpack/">Click here to Download SSIS PowerPack</a> and try it your self.</p>
<p><b>Keywords:</b><br />
<em>Loading data into MongoDB</em> | <em>mongodb upsert array</em> | <em>mongodb upsert example</em> | <em>mongodb insert or update</em> | <em>mongo insert or update</em> | <em>mongo upsert</em> | <em>mongo insert JSON</em> | <em>mongo upsert JSON | update data into MongoDB</em></p>
<p>The post <a href="https://zappysys.com/blog/ssis-loading-data-into-mongodb-upsert-update-delete-insert/">SSIS &#8211; Loading data into MongoDB (Upsert, Delete, Update)</a> appeared first on <a href="https://zappysys.com/blog">ZappySys Blog</a>.</p>
]]></content:encoded>
					
		
		
			</item>
		<item>
		<title>5 Ways to Export JSON from SQL Server using SSIS</title>
		<link>https://zappysys.com/blog/export-json-from-sql-server-using-ssis/</link>
		
		<dc:creator><![CDATA[ZappySys]]></dc:creator>
		<pubDate>Mon, 07 Dec 2015 19:38:44 +0000</pubDate>
				<category><![CDATA[SSIS JSON Export Task]]></category>
		<category><![CDATA[SSIS JSON File Destination]]></category>
		<category><![CDATA[SSIS JSON Generator Transform]]></category>
		<category><![CDATA[SSIS Logging Task]]></category>
		<category><![CDATA[SSIS Template Transform]]></category>
		<category><![CDATA[json]]></category>
		<category><![CDATA[sql server]]></category>
		<category><![CDATA[ssis]]></category>
		<category><![CDATA[SSIS Export JSON Task]]></category>
		<category><![CDATA[SSIS PowerPack]]></category>
		<guid isPermaLink="false">http://zappysys.com/blog/?p=209</guid>

					<description><![CDATA[<p>Introduction SQL Server 2012 and all previous versions lacking native JSON support, same theory is true for their ETL Platform SSIS. If you are one of them who wants to export JSON from SQL Server or any other RDBMS like MySQL, Oracle then you can easily output complex JSON using any of the following components. Five ways of [&#8230;]</p>
<p>The post <a href="https://zappysys.com/blog/export-json-from-sql-server-using-ssis/">5 Ways to Export JSON from SQL Server using SSIS</a> appeared first on <a href="https://zappysys.com/blog">ZappySys Blog</a>.</p>
]]></description>
										<content:encoded><![CDATA[<h2>Introduction</h2>
<p>SQL Server 2012 and all previous versions lacking native JSON support, same theory is true for their ETL Platform SSIS. If you are one of them who wants to export JSON from SQL Server or any other RDBMS like MySQL, Oracle then you can easily output complex JSON using any of the following components.</p>
<h2>Five ways of creating JSON inside SSIS</h2>
<p>ZappySys toolset provides multiple ways creating JSON inside SSIS. You can choose method suitable for your scenario. Each method has pros and cons so choose it as per your need.</p>
<h3>JSON File Destination</h3>
<p><img decoding="async" class="alignleft" style="font-family: inherit; font-size: inherit;" title="SSIS JSON Destination (Create JSON File)" src="https://zappysys.com/onlinehelp/ssis-powerpack/scr/images/json-file-destination/ssis-json-file-destination.png" alt="SSIS JSON Destination (Create JSON File)" width="100" /><a href="https://zappysys.com/products/ssis-powerpack/ssis-json-file-destination-connector/" target="_blank" rel="noopener">SSIS JSON Destination</a> can be used to generate simple or complex JSON files out of relational data source such as SQL Server, Oracle, MySQL. In few clicks you can create desired JSON Shape from single or multiple tables (Parent/Child Nested Documents).</p>
<p><strong>PROS:</strong> Multiple data flow components can be attached. Which means unlike <a href="https://zappysys.com/products/ssis-powerpack/ssis-export-json-file-task/" target="_blank" rel="noopener">Export JSON Task</a> you are not limited to OLEDB or ODBC Sources only.</p>
<p><strong>CONS:</strong> When you remove upstream component it may break Dataset mappings. Also server side Lookup Option is not available. File Splitting Options not available.</p>
<p>Here are <a href="https://zappysys.com/blog/category/ssis/components/ssis-json-file-destination/" target="_blank" rel="noopener">some articles</a> for use case of this component.</p>
<div id="attachment_5358" style="width: 943px" class="wp-caption alignnone"><a href="https://zappysys.com/blog/wp-content/uploads/2015/12/ssis-generate-json-using-dummy-root-multiple-input-source.png"><img loading="lazy" decoding="async" aria-describedby="caption-attachment-5358" class="size-full wp-image-5358" src="https://zappysys.com/blog/wp-content/uploads/2015/12/ssis-generate-json-using-dummy-root-multiple-input-source.png" alt="JSON File Destination - Generate JSON in SSIS from multiple inputs" width="933" height="784" srcset="https://zappysys.com/blog/wp-content/uploads/2015/12/ssis-generate-json-using-dummy-root-multiple-input-source.png 933w, https://zappysys.com/blog/wp-content/uploads/2015/12/ssis-generate-json-using-dummy-root-multiple-input-source-300x252.png 300w, https://zappysys.com/blog/wp-content/uploads/2015/12/ssis-generate-json-using-dummy-root-multiple-input-source-768x645.png 768w" sizes="(max-width: 933px) 100vw, 933px" /></a><p id="caption-attachment-5358" class="wp-caption-text">JSON File Destination &#8211; Generate JSON in SSIS from multiple inputs</p></div>
<h3>JSON Generator Transform</h3>
<h3><span style="font-size: 16px;"><img decoding="async" class="alignleft" title="JSON Generator Transform" src="https://zappysys.com/images/SSIS-PowerPack/ssis-json-generator-transform.png" alt="JSON Generator Transform" width="100" /></span></h3>
<p><a href="https://zappysys.com/products/ssis-powerpack/ssis-json-generator-transform/" target="_blank" rel="noopener">SSIS JSON Generator Transform</a> can be used to generate single or multiple JSON documents from any type of data sources (e.g. SQL Server, MySQL, Flat File, Excel) inside data flow task. It takes multiple inputs and outputs JSON String Output Column which can be used to feed JSON to other downstream system.</p>
<p><strong>PROS:</strong> Multiple data flow components can be attached. Which means unlike <a href="https://zappysys.com/products/ssis-powerpack/ssis-export-json-file-task/" target="_blank" rel="noopener">Export JSON Task</a> you are not limited to OLEDB or ODBC Sources only.</p>
<p><strong>CONS:</strong> When you remove upstream component it may break Dataset mappings. Also server side Lookup Option is not available. File Splitting Options not available. Output is JSON String Column.</p>
<p>Here are <a href="https://zappysys.com/blog/category/ssis/components/ssis-json-generator-transform/" target="_blank" rel="noopener">some articles</a> for use case of this transform.</p>
<div id="attachment_4918" style="width: 792px" class="wp-caption alignnone"><a href="https://zappysys.com/blog/wp-content/uploads/2017/07/ssis-preview-json-for-bigquery-dataset-insert.png"><img loading="lazy" decoding="async" aria-describedby="caption-attachment-4918" class="size-full wp-image-4918" src="https://zappysys.com/blog/wp-content/uploads/2017/07/ssis-preview-json-for-bigquery-dataset-insert.png" alt="Preview JSON - Generate for BigQuery Table Insert" width="782" height="640" srcset="https://zappysys.com/blog/wp-content/uploads/2017/07/ssis-preview-json-for-bigquery-dataset-insert.png 782w, https://zappysys.com/blog/wp-content/uploads/2017/07/ssis-preview-json-for-bigquery-dataset-insert-300x246.png 300w, https://zappysys.com/blog/wp-content/uploads/2017/07/ssis-preview-json-for-bigquery-dataset-insert-768x629.png 768w" sizes="(max-width: 782px) 100vw, 782px" /></a><p id="caption-attachment-4918" class="wp-caption-text">Preview JSON &#8211; Generate for BigQuery Table Insert</p></div>
<h3>Export JSON Task</h3>
<p><em><img decoding="async" class="alignleft" src="https://zappysys.com/images/SSIS-PowerPack/ssis-export-json-file-task.png" alt="SSIS Export JSON File Task" /></em><a href="https://zappysys.com/products/ssis-powerpack/ssis-export-json-file-task/" target="_blank" rel="noopener">SSIS Export JSON File Task</a> can be used to generate simple or complex JSON files out of relational data source such as SQL Server, Oracle, MySQL. It also support exporting directly to cloud (e.g. Azure Blob Storage, Amazon AWS S3, Secure FTP). In few clicks you can create desired JSON Shape from single or multiple tables (Parent/Child Nested Documents)</p>
<p><strong>PROS:</strong> Simple to use with flexible options to export to file, variable, AWS S3, Azure Blob, FTP / SFTP location. Allows to split records. File Splitting Options available (Split By Size  / Row Count).</p>
<p><strong>CONS:</strong> You can only use limited data sources as Dataset input (e.g. OLEDB / ODBC or SQL Server).</p>
<p>Here are <a href="https://zappysys.com/blog/category/ssis/tasks/ssis-json-export-task/" target="_blank" rel="noopener">some articles</a> for use case of this task.</p>
<h3>Template Transform</h3>
<p><img decoding="async" class="alignleft" src="https://zappysys.com/onlinehelp/ssis-powerpack/scr/images/template-transform/ssis-template-transform.png" alt="SSIS SSIS Template Transform" />Template Transform can be used to create dynamic strings inside data flow. You can use upstream columns as placeholders or use SSIS variables anywhere in the template to create desired text (e.g. XML / JSON document).</p>
<p><strong>PROS:</strong> Very Simple to use.</p>
<p><strong>CONS:</strong> Cannot use multiple inputs. It may not be used to create Complex JSON and options like do not output NULL attributes is not possible.</p>
<p>&nbsp;</p>
<p>Here are <a href="https://zappysys.com/blog/category/ssis/components/ssis-template-transform/" target="_blank" rel="noopener">some articles</a> for use case of this transform.</p>
<div id="attachment_2614" style="width: 983px" class="wp-caption alignnone"><a href="https://zappysys.com/blog/wp-content/uploads/2018/02/ssis-template-transform-create-json-xml-for-api-call.png"><img loading="lazy" decoding="async" aria-describedby="caption-attachment-2614" class="size-full wp-image-2614" src="https://zappysys.com/blog/wp-content/uploads/2018/02/ssis-template-transform-create-json-xml-for-api-call.png" alt="Create JSON for API Request (POST) using SSIS Template Transform" width="973" height="611" srcset="https://zappysys.com/blog/wp-content/uploads/2018/02/ssis-template-transform-create-json-xml-for-api-call.png 973w, https://zappysys.com/blog/wp-content/uploads/2018/02/ssis-template-transform-create-json-xml-for-api-call-300x188.png 300w, https://zappysys.com/blog/wp-content/uploads/2018/02/ssis-template-transform-create-json-xml-for-api-call-768x482.png 768w" sizes="(max-width: 973px) 100vw, 973px" /></a><p id="caption-attachment-2614" class="wp-caption-text">Create JSON for API Request (POST) using SSIS Template Transform</p></div>
<h3>Logging Task (Control Flow Approach)</h3>
<p><img decoding="async" class="alignleft" src="https://zappysys.com/images/SSIS-PowerPack/ssis-logging-task.png" /> Just like Template Transform you can use <a href="https://zappysys.com/products/ssis-powerpack/ssis-logging-task-free/" target="_blank" rel="noopener">ZS Logging Task</a> to create JSON string from Template and Variable Placeholders.</p>
<p>&nbsp;</p>
<p>&nbsp;</p>
<p>&nbsp;</p>
<p>Here is how to use Logging Task to save JSON into a variable.</p>
<ol>
<li>Select Variable which you like to Set on Logging Task</li>
<li>Enter your Template JSON String which you like to produce (see example below). Notice the use of yyyy-MM-dd <a href="https://zappysys.com/onlinehelp/ssis-powerpack/scr/ssis-format-specifiers.htm" target="_blank" rel="noopener">format specifier</a> and also JSONENCODE function.<br />
<pre class="crayon-plain-tag">{
 ActionId: {{User::vActionId}},
 CreatedOn: "{{User::vOrderDate,yyyy-MM-ddTHH:mm:ss}}",
 Notes: "{{User::vNotes,JSONENCODE}}"
}</pre>
</li>
<li>Select Message Type = <strong>None</strong></li>
<li><strong>Uncheck Append</strong>, and <strong>Prefix</strong> options like below
<div id="attachment_222" style="width: 732px" class="wp-caption alignnone"><a href="//zappysys.com/blog/wp-content/uploads/2015/12/set-ssis-variable-value-multi-line-placeholder.png"><img loading="lazy" decoding="async" aria-describedby="caption-attachment-222" class="wp-image-222 size-full" src="https://zappysys.com/blog/wp-content/uploads/2015/12/set-ssis-variable-value-multi-line-placeholder.png" alt="Creating JSON / XML Document using SSIS Logging Task" width="722" height="528" srcset="https://zappysys.com/blog/wp-content/uploads/2015/12/set-ssis-variable-value-multi-line-placeholder.png 722w, https://zappysys.com/blog/wp-content/uploads/2015/12/set-ssis-variable-value-multi-line-placeholder-300x219.png 300w" sizes="(max-width: 722px) 100vw, 722px" /></a><p id="caption-attachment-222" class="wp-caption-text">Creating JSON / XML Document using SSIS Logging Task</p></div></li>
</ol>
<p>&nbsp;</p>
<p>Here are <a href="https://zappysys.com/blog/category/ssis/tasks/ssis-logging-task/" target="_blank" rel="noopener">some articles</a> for use case of this task.</p>
<p>&nbsp;</p>
<h2>Create JSON using SSIS Export JSON Task</h2>
<p>Now let&#8217;s look at Export JSON Task form example to create JSON. Steps listed in below sections are very similar to JSON File Destination or JSON Generator Transform.</p>
<p>ZappySys offers innovative Layout Editor for JSON / XML creation from multiple sources. You can use Layout Editor to produce desired JSON Layout (Layout is stored in XML format behind the scene) and then in later step you will see how to make it dynamic so values are changed at runtime.</p>
<p>You can read layout as direct value, read from variable or read from file from disk.</p>
<h3>Select source connection for data</h3>
<p>First lets create new OLEDB or ADO.net connection from where we will read data. In our case we reading from Northwind Database.</p>
<div id="attachment_216" style="width: 565px" class="wp-caption alignnone"><a href="//zappysys.com/blog/wp-content/uploads/2015/12/ssis-export-json-task-source-connection.png"><img loading="lazy" decoding="async" aria-describedby="caption-attachment-216" class="size-full wp-image-216" src="//zappysys.com/blog/wp-content/uploads/2015/12/ssis-export-json-task-source-connection.png" alt="SSIS JSON Export Task - Select Source Database Connection" width="555" height="218" srcset="https://zappysys.com/blog/wp-content/uploads/2015/12/ssis-export-json-task-source-connection.png 555w, https://zappysys.com/blog/wp-content/uploads/2015/12/ssis-export-json-task-source-connection-300x118.png 300w" sizes="(max-width: 555px) 100vw, 555px" /></a><p id="caption-attachment-216" class="wp-caption-text">SSIS JSON Export Task &#8211; Select Source Database Connection</p></div>
<h3>Create Datasets</h3>
<p>Now add datasets which will be used to produce JSON File. One dataset will be always Root Dataset (Example: If your Root information is about customer then select customer table or query as your Main dataset. All other sections will be child sections)</p>
<div id="attachment_215" style="width: 419px" class="wp-caption alignnone"><a href="//zappysys.com/blog/wp-content/uploads/2015/12/ssis-json-output-from-sql-server-source-dataset.png"><img loading="lazy" decoding="async" aria-describedby="caption-attachment-215" class="size-full wp-image-215" src="//zappysys.com/blog/wp-content/uploads/2015/12/ssis-json-output-from-sql-server-source-dataset.png" alt="Add SQL Dataset - Export JSON from SQL Query Option" width="409" height="431" srcset="https://zappysys.com/blog/wp-content/uploads/2015/12/ssis-json-output-from-sql-server-source-dataset.png 409w, https://zappysys.com/blog/wp-content/uploads/2015/12/ssis-json-output-from-sql-server-source-dataset-285x300.png 285w" sizes="(max-width: 409px) 100vw, 409px" /></a><p id="caption-attachment-215" class="wp-caption-text">Add SQL Dataset &#8211; Export JSON from SQL Query Option</p></div>
<h3>Add Output Columns for Main JSON Document</h3>
<p>Now its time to add columns for our output. If * is added by default then remove. * means output all columns. When you add columns first make sure you select correct parent node under which you want to add columns. In our case &#8220;Mappings&#8221; is parent node.</p>
<div id="attachment_214" style="width: 391px" class="wp-caption alignnone"><a href="//zappysys.com/blog/wp-content/uploads/2015/12/ssis-json-output-from-sql-server-add-columns.png"><img loading="lazy" decoding="async" aria-describedby="caption-attachment-214" class="size-full wp-image-214" src="//zappysys.com/blog/wp-content/uploads/2015/12/ssis-json-output-from-sql-server-add-columns.png" alt="Add Output Columns for JSON Document - Column Selection Screen" width="381" height="446" srcset="https://zappysys.com/blog/wp-content/uploads/2015/12/ssis-json-output-from-sql-server-add-columns.png 381w, https://zappysys.com/blog/wp-content/uploads/2015/12/ssis-json-output-from-sql-server-add-columns-256x300.png 256w" sizes="(max-width: 381px) 100vw, 381px" /></a><p id="caption-attachment-214" class="wp-caption-text">Add Output Columns for JSON Document &#8211; Column Selection Screen</p></div>
<h3>Add JSON Array / JOIN Conditions for related document</h3>
<p>Now let&#8217;s look at how to add JSON Array. For example Customer may have one or more Orders so we need to add node called Orders which may Produce JSON fragment like below</p>
<pre class="crayon-plain-tag">Orders : [ {...} , {...} ] </pre>
<p>Once customer related columns added, its time to add Orders section.</p>
<ol>
<li>This is Array of documents so first highlight &#8220;Mappings&#8221; node</li>
<li>Click &#8220;Add Document Array&#8221; option from toolbar.</li>
<li>On Add/Edit Elements UI specify name for JSON Attribute and specify correct relationship to parent dataset. In our case Orders related to Customers using CustomerID key.</li>
</ol>
<div id="attachment_212" style="width: 548px" class="wp-caption alignnone"><a href="//zappysys.com/blog/wp-content/uploads/2015/12/ssis-json-output-from-sql-server-parent-child-relation.png"><img loading="lazy" decoding="async" aria-describedby="caption-attachment-212" class="size-full wp-image-212" src="//zappysys.com/blog/wp-content/uploads/2015/12/ssis-json-output-from-sql-server-parent-child-relation.png" alt="Add Child Section - nested JSON document , Define Parent-Child Relationship" width="538" height="432" srcset="https://zappysys.com/blog/wp-content/uploads/2015/12/ssis-json-output-from-sql-server-parent-child-relation.png 538w, https://zappysys.com/blog/wp-content/uploads/2015/12/ssis-json-output-from-sql-server-parent-child-relation-300x241.png 300w" sizes="(max-width: 538px) 100vw, 538px" /></a><p id="caption-attachment-212" class="wp-caption-text">Add Child Section &#8211; nested JSON document , Define Parent-Child Relationship</p></div>
<h3>Handling JSON Array with dummy root dataset (Multiple Arrays)</h3>
<p>So in previous section we saw how to add array and define JOIN condition with parent dataset. Now what if you really have no parent dataset to join with ? For example we need to produce following sample JSON where Order array is related to Customer by common Column CustomerID as JOIN column. But Customer is not bound with any parent column. So how do you define JOIN condition? In such case you have to use below technique called dummy root dataset. (See next section on how to handle only one dataset using <strong>Single Dataset Array Mode</strong>)</p>
<p><strong>Sample JSON (Dummy root pattern)</strong></p><pre class="crayon-plain-tag">{
    "Customers": [
      {
        "CustomerID": "ALFKI",
        "CompanyName": "Alfreds Futterkiste",
        "Orders": [
          {
            "OrderID": 1000,
            "OrderDate": "2015-12-01"
          },
          {
            "OrderID": 1001,
            "OrderDate": "2015-12-01"
          }
        ]
      },

      {
        "CustomerID": "ANATR",
        "CompanyName": "Ana Trujillo Emparedados y helados",
        "Orders": [
          {
            "OrderID": 1002,
            "OrderDate": "2015-12-01"
          },
          {
            "OrderID": 1003,
            "OrderDate": "2015-12-01"
          }
        ]
      }

    ]
  }
}</pre><p>
Since root level always needs dataset, we must provide dummy dataset (only one row) even though there is no need for Parent Dataset JOIN in Customer Array. Typically you can write query like below to product dummy row in SQL Server or other database using OLEDB Source or Use <a href="https://zappysys.com/products/ssis-powerpack/dummy-data-source-free/" target="_blank" rel="noopener">Dummy Data Source</a> with Max Rows=1 setting to produce one fake record.</p><pre class="crayon-plain-tag">SELECT 1 as Col1</pre><p>
<strong>Using Dummy DataSource as Input</strong></p>
<p>For generating JSON which needs dummy root. Perform the following steps</p>
<ol>
<li>Drag Dummy Data Source from SSIS Toolbox. Change <strong>How many rows</strong> to 1. Click OK</li>
<li>Now drag two more OLEDB sources and Configure (e.g. Customers and Orders)</li>
<li>Now drag <a href="https://zappysys.com/products/ssis-powerpack/ssis-json-file-destination-connector/">ZS JSON FIle Destination</a> component or <a href="https://zappysys.com/products/ssis-powerpack/ssis-json-generator-transform/">ZS JSON Generator</a></li>
<li>Now connect Dummy datasource then Customers and then Orders</li>
<li>Double click JSON component to configure layout. You may notice that Dummy Input is set as Root by default.</li>
<li>You can now select Mappings node and click on Add Array Documents icon. Configure like below. Notice we have not selected any JOIN criteria because its joined with Dummy Root.
<div id="attachment_5357" style="width: 785px" class="wp-caption alignnone"><a href="https://zappysys.com/blog/wp-content/uploads/2015/12/dummy-root-pattern-ssis-json-export.png"><img loading="lazy" decoding="async" aria-describedby="caption-attachment-5357" class="size-full wp-image-5357" src="https://zappysys.com/blog/wp-content/uploads/2015/12/dummy-root-pattern-ssis-json-export.png" alt="Add array to join with dummy dataset" width="775" height="617" srcset="https://zappysys.com/blog/wp-content/uploads/2015/12/dummy-root-pattern-ssis-json-export.png 775w, https://zappysys.com/blog/wp-content/uploads/2015/12/dummy-root-pattern-ssis-json-export-300x239.png 300w, https://zappysys.com/blog/wp-content/uploads/2015/12/dummy-root-pattern-ssis-json-export-768x611.png 768w" sizes="(max-width: 775px) 100vw, 775px" /></a><p id="caption-attachment-5357" class="wp-caption-text">Add array to join with dummy dataset</p></div></li>
<li>Now select newly added node and Click Add column icon to add CustomerID, CompanyName column under Customers array</li>
<li>Now select Customers array node and click Array Documents icon to Add Orders array.</li>
<li>Once Orders Array ia added you can Select Orders node and Insert new element to add OrderID and OrderDate columns</li>
<li>Finally it will look like below
<div id="attachment_5358" style="width: 943px" class="wp-caption alignnone"><a href="https://zappysys.com/blog/wp-content/uploads/2015/12/ssis-generate-json-using-dummy-root-multiple-input-source.png"><img loading="lazy" decoding="async" aria-describedby="caption-attachment-5358" class="size-full wp-image-5358" src="https://zappysys.com/blog/wp-content/uploads/2015/12/ssis-generate-json-using-dummy-root-multiple-input-source.png" alt="JSON File Destination - Generate JSON in SSIS from multiple inputs" width="933" height="784" srcset="https://zappysys.com/blog/wp-content/uploads/2015/12/ssis-generate-json-using-dummy-root-multiple-input-source.png 933w, https://zappysys.com/blog/wp-content/uploads/2015/12/ssis-generate-json-using-dummy-root-multiple-input-source-300x252.png 300w, https://zappysys.com/blog/wp-content/uploads/2015/12/ssis-generate-json-using-dummy-root-multiple-input-source-768x645.png 768w" sizes="(max-width: 933px) 100vw, 933px" /></a><p id="caption-attachment-5358" class="wp-caption-text">JSON File Destination &#8211; Generate JSON in SSIS from multiple inputs</p></div></li>
</ol>
<p>&nbsp;</p>
<h3>Single dataset used as array</h3>
<p>Now lets look at one more pattern just like described in the previous section but now we have just one nested level (Only customers and not using Orders). If you have such case then choose Single dataset pattern option in the output mode. On Export Task you may see as check box rather than dropdown. To produced desired JSON (see blow) perform these steps.</p>
<ol>
<li>Select Output mode as <strong>Single Dataset Array</strong></li>
<li>In your Layout builder click on <strong>Add Document Array</strong> Icon and name it &#8220;Customers&#8221;.</li>
<li>After that highlight newly added node &gt; Right-Click &gt; <strong>Add Elements</strong> under that node</li>
<li>That&#8217;s it you will now see preview like below.</li>
</ol>
<pre class="crayon-plain-tag">{
    "Customers": [
      {
        "CustomerID": "ALFKI",
        "CompanyName": "Alfreds Futterkiste"
      },

      {
        "CustomerID": "ANATR",
        "CompanyName": "Ana Trujillo Emparedados y helados"
      }
    ]
  }
}</pre>
&nbsp;</p>
<h3>How to export JSON in 2D Array format</h3>
<p>If you have to export JSON as 2D array format then you can change following option.</p>
<p><img decoding="async" class="figureimage" title="SSIS Export to JSON File Task - Export as 2D Array" src="https://zappysys.com/onlinehelp/ssis-powerpack/scr/images/export-json-file-task/ssis-export-json-2d-array-format.png" alt="SSIS Export JSON File Task - Export as 2D Array" /></p>
<p>Here are examples of output for each option.<br />
Select say you have source data with 2 columns <i>id</i> and <i>name</i>.</p>
<p><b>Default</b></p><pre class="crayon-plain-tag">[{id:1,name:&quot;AA&quot;}, {id:2,name:&quot;BB&quot;}]</pre><p>
<b>Multicontent</b></p><pre class="crayon-plain-tag">{id:1,name:&quot;AA&quot;}{id:2,name:&quot;BB&quot;}</pre><p>
<b>ArrayDocs</b></p><pre class="crayon-plain-tag">[{id:1,name:&quot;AA&quot;}, {id:2,name:&quot;BB&quot;}]</pre><p>
<b>Array2D</b></p><pre class="crayon-plain-tag">[[1,&quot;AA&quot;],[2,&quot;BB&quot;]]</pre><p>
<b>Array2DWithHeader</b></p><pre class="crayon-plain-tag">[[&quot;id&quot;,&quot;name&quot;],[1,&quot;AA&quot;],[2,&quot;BB&quot;]]</pre><p>
<b>ArrayLines</b></p><pre class="crayon-plain-tag">[1,&quot;AA&quot;][2,&quot;BB&quot;]</pre><p>
<b>ArrayLinesWithHeader</b></p><pre class="crayon-plain-tag">[&quot;id&quot;,&quot;name&quot;][1,&quot;AA&quot;][2,&quot;BB&quot;]</pre><p>
&nbsp;</p>
<h3>Preview JSON output using live preview</h3>
<p>You can enable / disable Live preview of JSON layout as below.</p>
<div id="attachment_210" style="width: 573px" class="wp-caption alignnone"><a href="//zappysys.com/blog/wp-content/uploads/2015/12/sql-server-json-output-preview-ssis.png"><img loading="lazy" decoding="async" aria-describedby="caption-attachment-210" class="size-full wp-image-210" src="//zappysys.com/blog/wp-content/uploads/2015/12/sql-server-json-output-preview-ssis.png" alt="JSON Output preview in SSIS Export JSON File Task" width="563" height="475" srcset="https://zappysys.com/blog/wp-content/uploads/2015/12/sql-server-json-output-preview-ssis.png 563w, https://zappysys.com/blog/wp-content/uploads/2015/12/sql-server-json-output-preview-ssis-300x253.png 300w" sizes="(max-width: 563px) 100vw, 563px" /></a><p id="caption-attachment-210" class="wp-caption-text">JSON Output preview in SSIS Export JSON File Task</p></div>
<h2>Make things dynamic (Using SSIS Variable for SQL or Layout)</h2>
<p>There will be a time when you have use dynamic values in your JSON generation. You may have to Alias something from variable or you have to supply Variable in your SQL used for Dataset. Not to worry. ZappySys Supports multiple ways to make it dynamic. You can use SSIS Variables following 3 ways to make Layout XML dynamic.</p>
<ol>
<li>Use SSIS variable inside Dataset SQL (Only for <a href="https://zappysys.com/products/ssis-powerpack/ssis-export-json-file-task/" target="_blank" rel="noopener">ZS Export JSON Task</a>)</li>
<li>Anywhere inside Layout XML (Click <strong>Edit Code</strong> option)</li>
<li>Load Layout From Variable (Indirect Method)</li>
</ol>
<h3>Using Variable inside Dataset SQL</h3>
<p>Here is how you can use Variable inside dataset SQL for <a href="https://zappysys.com/products/ssis-powerpack/ssis-export-json-file-task/" target="_blank" rel="noopener">ZS Export JSON Task</a></p>
<div id="attachment_5359" style="width: 736px" class="wp-caption alignnone"><a href="https://zappysys.com/blog/wp-content/uploads/2015/12/ssis-export-json-dynamic-dataset-sql-use-variable.png"><img loading="lazy" decoding="async" aria-describedby="caption-attachment-5359" class="size-full wp-image-5359" src="https://zappysys.com/blog/wp-content/uploads/2015/12/ssis-export-json-dynamic-dataset-sql-use-variable.png" alt="SSIS Export JSON Task - Using Variable for Dynamic SQL" width="726" height="538" srcset="https://zappysys.com/blog/wp-content/uploads/2015/12/ssis-export-json-dynamic-dataset-sql-use-variable.png 726w, https://zappysys.com/blog/wp-content/uploads/2015/12/ssis-export-json-dynamic-dataset-sql-use-variable-300x222.png 300w" sizes="(max-width: 726px) 100vw, 726px" /></a><p id="caption-attachment-5359" class="wp-caption-text">SSIS Export JSON Task &#8211; Using Variable for Dynamic SQL</p></div>
<h3>Using Variable inside Layout XML</h3>
<p>Here is how you can insert SSIS Variable anywhere in Layout XML. In below Example we are choosing Alias for one column from some SSIS Variable.</p>
<div id="attachment_5360" style="width: 865px" class="wp-caption alignnone"><a href="https://zappysys.com/blog/wp-content/uploads/2015/12/ssis-json-file-destination-use-ssis-variable-dynamic-layout.png"><img loading="lazy" decoding="async" aria-describedby="caption-attachment-5360" class="size-full wp-image-5360" src="https://zappysys.com/blog/wp-content/uploads/2015/12/ssis-json-file-destination-use-ssis-variable-dynamic-layout.png" alt="SSIS JSON File Destination - Using SSIS Variable for Dynamic Layout" width="855" height="591" srcset="https://zappysys.com/blog/wp-content/uploads/2015/12/ssis-json-file-destination-use-ssis-variable-dynamic-layout.png 855w, https://zappysys.com/blog/wp-content/uploads/2015/12/ssis-json-file-destination-use-ssis-variable-dynamic-layout-300x207.png 300w, https://zappysys.com/blog/wp-content/uploads/2015/12/ssis-json-file-destination-use-ssis-variable-dynamic-layout-768x531.png 768w" sizes="(max-width: 855px) 100vw, 855px" /></a><p id="caption-attachment-5360" class="wp-caption-text">SSIS JSON File Destination &#8211; Using SSIS Variable for Dynamic Layout</p></div>
<h3>Load Layout From Variable</h3>
<p>If you have some need to load Layout XML from File or SSIS Variable. You can use Load Layout from Variable Option.</p>
<p>For example in below screenshot we are creating layout first and ave to some variable. Or you can load from external file using <a href="https://zappysys.com/products/ssis-powerpack/ssis-file-system-task-advanced/">ZS Advanced File System Task</a>.  Connect Logging task to Export JSON Task and you ready to produce JSON.</p>
<div id="attachment_222" style="width: 732px" class="wp-caption alignnone"><a href="//zappysys.com/blog/wp-content/uploads/2015/12/set-ssis-variable-value-multi-line-placeholder.png"><img loading="lazy" decoding="async" aria-describedby="caption-attachment-222" class="size-full wp-image-222" src="//zappysys.com/blog/wp-content/uploads/2015/12/set-ssis-variable-value-multi-line-placeholder.png" alt="Set SSIS Variable value (multi-line content using placeholder)" width="722" height="528" srcset="https://zappysys.com/blog/wp-content/uploads/2015/12/set-ssis-variable-value-multi-line-placeholder.png 722w, https://zappysys.com/blog/wp-content/uploads/2015/12/set-ssis-variable-value-multi-line-placeholder-300x219.png 300w" sizes="(max-width: 722px) 100vw, 722px" /></a><p id="caption-attachment-222" class="wp-caption-text">Set SSIS Variable value (multi-line content using placeholder)</p></div>
<p>Here is how to load Layout From any SSIS Variable. You can also load Layout from XML file or Variable which contains layout File Path.</p>
<div id="attachment_210" style="width: 573px" class="wp-caption alignnone"><a href="//zappysys.com/blog/wp-content/uploads/2015/12/sql-server-json-output-preview-ssis.png"><img loading="lazy" decoding="async" aria-describedby="caption-attachment-210" class="wp-image-210 size-full" src="https://zappysys.com/blog/wp-content/uploads/2015/12/sql-server-json-output-preview-ssis.png" alt="JSON Layout from SSIS Variable" width="563" height="475" srcset="https://zappysys.com/blog/wp-content/uploads/2015/12/sql-server-json-output-preview-ssis.png 563w, https://zappysys.com/blog/wp-content/uploads/2015/12/sql-server-json-output-preview-ssis-300x253.png 300w" sizes="(max-width: 563px) 100vw, 563px" /></a><p id="caption-attachment-210" class="wp-caption-text">JSON Layout from SSIS Variable</p></div>
<h2>Other JSON Output Options</h2>
<p>Execute package and verify generated JSON it should look like below (Date format may be different in your case if you have set different on JSON options tab). For clarity we have formatted JSON below but in your output it may be compact version so reduce file size.</p>
<h3>Indent JSON Output</h3>
<p>You can check Indent option to make JSON look pretty like below.</p><pre class="crayon-plain-tag">{
  "CustomerID": "ALFKI",
  "CompanyName": "Alfreds Futterkiste",
  "ContactName": null,
  "Orders": [
    {
      "OrderID": 10643,
      "OrderDate": "1997-08-25T00:00:00"
    },
    {
      "OrderID": 10692,
      "OrderDate": "1997-10-03T00:00:00"
    },
    {
      "OrderID": 10702,
      "OrderDate": "1997-10-13T00:00:00"
    },
    {
      "OrderID": 10835,
      "OrderDate": "1998-01-15T00:00:00"
    },
    {
      "OrderID": 10952,
      "OrderDate": "1998-03-16T00:00:00"
    },
    {
      "OrderID": 11011,
      "OrderDate": "1998-04-09T00:00:00"
    }
  ]
}</pre><p>
<h3>Hide NULL Attribute Option</h3>
<p>There will be a time when you want to Hide NULL attribute rather than showing <strong>MyAttr: null</strong> this is also possible by checking Hide NULL Attribute Option on Options Tab.</p>
<h2>Export JSON to Amazon S3, Azure Blob, Secure FTP (SFTP / FTPS)</h2>
<p>Export JSON Task support some really good options to save file to other than local file system. If you want to export JSON directly to Amazon / Azure Cloud or FTP Server without saving to local disk then you can use Azure / FTP / Amazon Connection Manager on Target Tab of Export JSON Task. This option is only available for <strong>PRO Edition</strong> Users.</p>
<div style="width: 666px" class="wp-caption alignnone"><img loading="lazy" decoding="async" class="size-full" src="https://zappysys.com/onlinehelp/ssis-powerpack/scr/images/export-json-file-task/ssis-export-sql-tables-to-json-file-azure-blob-amazon-s3-secure-ftp-split-gzip-compress.png" alt="Export JSON / CSV / XML Files to Azure Blob, Amazon S3, Secure FTP Storage" width="656" height="440" /><p class="wp-caption-text">Export JSON / CSV / XML Files to Azure Blob, Amazon S3, Secure FTP Storage</p></div>
<h2>Conclusion</h2>
<p>If you want to output JSON from SQL Server or any other relational DB then its not simple task in SSIS specially when you have nested JSON documents (e.g. Customer-&gt;Orders). In this post you have seen how to use <a href="//zappysys.com/products/ssis-powerpack/ssis-export-json-file-task/">SSIS JSON Export Task</a> to generate nested JSON from multiple datasets.</p>
<p>The post <a href="https://zappysys.com/blog/export-json-from-sql-server-using-ssis/">5 Ways to Export JSON from SQL Server using SSIS</a> appeared first on <a href="https://zappysys.com/blog">ZappySys Blog</a>.</p>
]]></content:encoded>
					
		
		
			</item>
	</channel>
</rss>
