<?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>JSON &#8211; Database Research &amp; Development</title>
	<atom:link href="https://www.dbrnd.com/tag/json/feed/" rel="self" type="application/rss+xml" />
	<link>https://www.dbrnd.com</link>
	<description>BIGData &#124; NoSQL &#124; MSSQL &#124; MySQL &#124; PostgreSQL</description>
	<lastBuildDate>Wed, 23 Aug 2017 18:13:20 +0000</lastBuildDate>
	<language>en-US</language>
	<sy:updatePeriod>
	hourly	</sy:updatePeriod>
	<sy:updateFrequency>
	1	</sy:updateFrequency>
	<generator>https://wordpress.org/?v=7.0.6</generator>
	<item>
		<title>SQL Server 2016: Generate the JSON formatted data from the Table Data</title>
		<link>https://www.dbrnd.com/2017/08/sql-server-2016-generate-the-json-formatted-data-from-the-table-data-for-json-auto/</link>
		
		<dc:creator><![CDATA[Anvesh Patel]]></dc:creator>
		<pubDate>Thu, 31 Aug 2017 16:16:22 +0000</pubDate>
				<category><![CDATA[SQL Server]]></category>
		<category><![CDATA[Anvesh Patel]]></category>
		<category><![CDATA[database]]></category>
		<category><![CDATA[database research and development]]></category>
		<category><![CDATA[dbrnd]]></category>
		<category><![CDATA[FOR JSON AUTO]]></category>
		<category><![CDATA[JSON]]></category>
		<category><![CDATA[SQL Query]]></category>
		<category><![CDATA[SQL Server 2016]]></category>
		<category><![CDATA[SQL Server Administrator]]></category>
		<category><![CDATA[SQL Server Error]]></category>
		<category><![CDATA[SQL Server Monitoring]]></category>
		<category><![CDATA[SQL Server Performance Tuning]]></category>
		<category><![CDATA[SQL Server Programming]]></category>
		<category><![CDATA[SQL Server Tips and Tricks]]></category>
		<category><![CDATA[TSQL]]></category>
		<guid isPermaLink="false">https://www.dbrnd.com/?p=6008</guid>

					<description><![CDATA[SQL Server 2016 introduced compelling data type called JSON data type. It also added a variety of new operators and functions related to JSON data type. This is one of the interesting topics for us, and I have recently published a series of articles on SQL Server JSON Data type. SQL Server 2016: Introduced JSON [&#8230;]]]></description>
										<content:encoded><![CDATA[<p><a class="a2a_button_facebook" href="https://www.addtoany.com/add_to/facebook?linkurl=https%3A%2F%2Fwww.dbrnd.com%2F2017%2F08%2Fsql-server-2016-generate-the-json-formatted-data-from-the-table-data-for-json-auto%2F&amp;linkname=SQL%20Server%202016%3A%20Generate%20the%20JSON%20formatted%20data%20from%20the%20Table%20Data" title="Facebook" rel="nofollow noopener" target="_blank"></a><a class="a2a_button_twitter" href="https://www.addtoany.com/add_to/twitter?linkurl=https%3A%2F%2Fwww.dbrnd.com%2F2017%2F08%2Fsql-server-2016-generate-the-json-formatted-data-from-the-table-data-for-json-auto%2F&amp;linkname=SQL%20Server%202016%3A%20Generate%20the%20JSON%20formatted%20data%20from%20the%20Table%20Data" title="Twitter" rel="nofollow noopener" target="_blank"></a><a class="a2a_button_linkedin" href="https://www.addtoany.com/add_to/linkedin?linkurl=https%3A%2F%2Fwww.dbrnd.com%2F2017%2F08%2Fsql-server-2016-generate-the-json-formatted-data-from-the-table-data-for-json-auto%2F&amp;linkname=SQL%20Server%202016%3A%20Generate%20the%20JSON%20formatted%20data%20from%20the%20Table%20Data" title="LinkedIn" rel="nofollow noopener" target="_blank"></a><a class="a2a_button_pinterest" href="https://www.addtoany.com/add_to/pinterest?linkurl=https%3A%2F%2Fwww.dbrnd.com%2F2017%2F08%2Fsql-server-2016-generate-the-json-formatted-data-from-the-table-data-for-json-auto%2F&amp;linkname=SQL%20Server%202016%3A%20Generate%20the%20JSON%20formatted%20data%20from%20the%20Table%20Data" title="Pinterest" rel="nofollow noopener" target="_blank"></a><a class="a2a_button_reddit" href="https://www.addtoany.com/add_to/reddit?linkurl=https%3A%2F%2Fwww.dbrnd.com%2F2017%2F08%2Fsql-server-2016-generate-the-json-formatted-data-from-the-table-data-for-json-auto%2F&amp;linkname=SQL%20Server%202016%3A%20Generate%20the%20JSON%20formatted%20data%20from%20the%20Table%20Data" title="Reddit" rel="nofollow noopener" target="_blank"></a><a class="a2a_button_pocket" href="https://www.addtoany.com/add_to/pocket?linkurl=https%3A%2F%2Fwww.dbrnd.com%2F2017%2F08%2Fsql-server-2016-generate-the-json-formatted-data-from-the-table-data-for-json-auto%2F&amp;linkname=SQL%20Server%202016%3A%20Generate%20the%20JSON%20formatted%20data%20from%20the%20Table%20Data" title="Pocket" rel="nofollow noopener" target="_blank"></a><a class="a2a_dd addtoany_share_save addtoany_share" href="https://www.addtoany.com/share#url=https%3A%2F%2Fwww.dbrnd.com%2F2017%2F08%2Fsql-server-2016-generate-the-json-formatted-data-from-the-table-data-for-json-auto%2F&#038;title=SQL%20Server%202016%3A%20Generate%20the%20JSON%20formatted%20data%20from%20the%20Table%20Data" data-a2a-url="https://www.dbrnd.com/2017/08/sql-server-2016-generate-the-json-formatted-data-from-the-table-data-for-json-auto/" data-a2a-title="SQL Server 2016: Generate the JSON formatted data from the Table Data"></a></p><p>SQL Server 2016 introduced compelling data type called JSON data type. It also added a variety of new operators and functions related to JSON data type.</p>
<p>This is one of the interesting topics for us, and I have recently published a series of articles on SQL Server JSON Data type.</p>
<blockquote data-secret="NutKpaNf5I" class="wp-embedded-content"><p><a href="https://www.dbrnd.com/2016/12/sql-server-2016-introduced-json-support-to-store-and-retrieve-json-document-isjson-json_value-json_query/">SQL Server 2016: Introduced JSON support, to store and retrieve JSON document</a></p></blockquote>
<p><iframe class="wp-embedded-content" sandbox="allow-scripts" security="restricted"  src="https://www.dbrnd.com/2016/12/sql-server-2016-introduced-json-support-to-store-and-retrieve-json-document-isjson-json_value-json_query/embed/#?secret=NutKpaNf5I" data-secret="NutKpaNf5I" width="600" height="338" title="&#8220;SQL Server 2016: Introduced JSON support, to store and retrieve JSON document&#8221; &#8212; Database Research &amp; Development" frameborder="0" marginwidth="0" marginheight="0" scrolling="no"></iframe></p>
<p>In this post, I am sharing one of the relevant queries to convert SQL Server tabular data into JSON formatted data.</p>
<blockquote><p>We are storing JSON formatted data into database and access base on the different filters.</p>
<p>Here, I am sharing one type of utility script to convert your table data into JSON formatted data.<br />
Sometimes it requires populating JSON formatted data for a web service purpose.</p></blockquote>
<p><strong>Create a sample table with data:</strong></p>
<pre class="crayon-plain-tag">CREATE TABLE tbl_Employees
(
	EmpID INT
	,EmpName VARCHAR(10)
	,EmpSalary INT
	,EmpDOJ DATE
)
GO

INSERT INTO tbl_Employees
VALUES
(1,'Anvesh',150000,'2017-01-01')
,(2,'Neevan',125000,'2016-01-01')
,(3,'Martin',90000,'2014-01-01')
,(4,'Roy',175000,'2014-05-08')
,(5,'Maria',60000,'2016-08-10')
,(6,'Jenny',40000,'2016-11-05')
GO</pre> </p>
<p><strong>Use FOR JSON AUTO, and generate the JSON formatted data:</strong></p>
<pre class="crayon-plain-tag">SELECT 
	EmpID
	,EmpName
	,EmpSalary
	,EmpDOJ
FROM tbl_Employees
FOR JSON AUTO</pre> </p>
<p><strong>Result:</strong></p>
<pre class="crayon-plain-tag">[
{"EmpID":1,"EmpName":"Anvesh","EmpSalary":150000,"EmpDOJ":"2017-01-01"}
,{"EmpID":2,"EmpName":"Neevan","EmpSalary":125000,"EmpDOJ":"2016-01-01"}
,{"EmpID":3,"EmpName":"Martin","EmpSalary":90000,"EmpDOJ":"2014-01-01"}
,{"EmpID":4,"EmpName":"Roy","EmpSalary":175000,"EmpDOJ":"2014-05-08"}
,{"EmpID":5,"EmpName":"Maria","EmpSalary":60000,"EmpDOJ":"2016-08-10"}
,{"EmpID":6,"EmpName":"Jenny","EmpSalary":40000,"EmpDOJ":"2016-11-05"}
]</pre> </p>
<p><strong>Use ROOT option, and generate the JSON formatted data:</strong></p>
<pre class="crayon-plain-tag">SELECT 
	EmpID
	,EmpName
	,EmpSalary
	,EmpDOJ
FROM tbl_Employees
FOR JSON PATH, ROOT ('Employee_Root')</pre> </p>
<p><strong>Result:</strong></p>
<pre class="crayon-plain-tag">{"Employee_Root":
	[
	{"EmpID":1,"EmpName":"Anvesh","EmpSalary":150000,"EmpDOJ":"2017-01-01"}
	,{"EmpID":2,"EmpName":"Neevan","EmpSalary":125000,"EmpDOJ":"2016-01-01"}
	,{"EmpID":3,"EmpName":"Martin","EmpSalary":90000,"EmpDOJ":"2014-01-01"}
	,{"EmpID":4,"EmpName":"Roy","EmpSalary":175000,"EmpDOJ":"2014-05-08"}
	,{"EmpID":5,"EmpName":"Maria","EmpSalary":60000,"EmpDOJ":"2016-08-10"}
	,{"EmpID":6,"EmpName":"Jenny","EmpSalary":40000,"EmpDOJ":"2016-11-05"}
	]
}</pre> </p>
]]></content:encoded>
					
		
		
			</item>
		<item>
		<title>SQL Server 2016: Use OPENJSON() to extract JSON data from Input Parameter</title>
		<link>https://www.dbrnd.com/2017/07/sql-server-2016-use-openjson-to-extract-json-data-from-input-parameter/</link>
		
		<dc:creator><![CDATA[Anvesh Patel]]></dc:creator>
		<pubDate>Tue, 18 Jul 2017 16:16:00 +0000</pubDate>
				<category><![CDATA[SQL Server]]></category>
		<category><![CDATA[Anvesh Patel]]></category>
		<category><![CDATA[database]]></category>
		<category><![CDATA[database research and development]]></category>
		<category><![CDATA[dbrnd]]></category>
		<category><![CDATA[JSON]]></category>
		<category><![CDATA[OPENJSON]]></category>
		<category><![CDATA[Parameter]]></category>
		<category><![CDATA[SQL Query]]></category>
		<category><![CDATA[SQL Server 2016]]></category>
		<category><![CDATA[SQL Server Administrator]]></category>
		<category><![CDATA[SQL Server Error]]></category>
		<category><![CDATA[SQL Server Monitoring]]></category>
		<category><![CDATA[SQL Server Performance Tuning]]></category>
		<category><![CDATA[SQL Server Programming]]></category>
		<category><![CDATA[SQL Server Tips and Tricks]]></category>
		<category><![CDATA[TSQL]]></category>
		<guid isPermaLink="false">https://www.dbrnd.com/?p=5636</guid>

					<description><![CDATA[SQL Server 2016 introduced the support of JSON and added many new functions in the recent CTP3 version of SQL Server 2016. Now, we have OPENJSON() to extract JSON data into a tabular format. If you are passing JSON document as an input parameter in Stored Procedure, you can use OPENJSON() to extract the value [&#8230;]]]></description>
										<content:encoded><![CDATA[<p><a class="a2a_button_facebook" href="https://www.addtoany.com/add_to/facebook?linkurl=https%3A%2F%2Fwww.dbrnd.com%2F2017%2F07%2Fsql-server-2016-use-openjson-to-extract-json-data-from-input-parameter%2F&amp;linkname=SQL%20Server%202016%3A%20Use%20OPENJSON%28%29%20to%20extract%20JSON%20data%20from%20Input%20Parameter" title="Facebook" rel="nofollow noopener" target="_blank"></a><a class="a2a_button_twitter" href="https://www.addtoany.com/add_to/twitter?linkurl=https%3A%2F%2Fwww.dbrnd.com%2F2017%2F07%2Fsql-server-2016-use-openjson-to-extract-json-data-from-input-parameter%2F&amp;linkname=SQL%20Server%202016%3A%20Use%20OPENJSON%28%29%20to%20extract%20JSON%20data%20from%20Input%20Parameter" title="Twitter" rel="nofollow noopener" target="_blank"></a><a class="a2a_button_linkedin" href="https://www.addtoany.com/add_to/linkedin?linkurl=https%3A%2F%2Fwww.dbrnd.com%2F2017%2F07%2Fsql-server-2016-use-openjson-to-extract-json-data-from-input-parameter%2F&amp;linkname=SQL%20Server%202016%3A%20Use%20OPENJSON%28%29%20to%20extract%20JSON%20data%20from%20Input%20Parameter" title="LinkedIn" rel="nofollow noopener" target="_blank"></a><a class="a2a_button_pinterest" href="https://www.addtoany.com/add_to/pinterest?linkurl=https%3A%2F%2Fwww.dbrnd.com%2F2017%2F07%2Fsql-server-2016-use-openjson-to-extract-json-data-from-input-parameter%2F&amp;linkname=SQL%20Server%202016%3A%20Use%20OPENJSON%28%29%20to%20extract%20JSON%20data%20from%20Input%20Parameter" title="Pinterest" rel="nofollow noopener" target="_blank"></a><a class="a2a_button_reddit" href="https://www.addtoany.com/add_to/reddit?linkurl=https%3A%2F%2Fwww.dbrnd.com%2F2017%2F07%2Fsql-server-2016-use-openjson-to-extract-json-data-from-input-parameter%2F&amp;linkname=SQL%20Server%202016%3A%20Use%20OPENJSON%28%29%20to%20extract%20JSON%20data%20from%20Input%20Parameter" title="Reddit" rel="nofollow noopener" target="_blank"></a><a class="a2a_button_pocket" href="https://www.addtoany.com/add_to/pocket?linkurl=https%3A%2F%2Fwww.dbrnd.com%2F2017%2F07%2Fsql-server-2016-use-openjson-to-extract-json-data-from-input-parameter%2F&amp;linkname=SQL%20Server%202016%3A%20Use%20OPENJSON%28%29%20to%20extract%20JSON%20data%20from%20Input%20Parameter" title="Pocket" rel="nofollow noopener" target="_blank"></a><a class="a2a_dd addtoany_share_save addtoany_share" href="https://www.addtoany.com/share#url=https%3A%2F%2Fwww.dbrnd.com%2F2017%2F07%2Fsql-server-2016-use-openjson-to-extract-json-data-from-input-parameter%2F&#038;title=SQL%20Server%202016%3A%20Use%20OPENJSON%28%29%20to%20extract%20JSON%20data%20from%20Input%20Parameter" data-a2a-url="https://www.dbrnd.com/2017/07/sql-server-2016-use-openjson-to-extract-json-data-from-input-parameter/" data-a2a-title="SQL Server 2016: Use OPENJSON() to extract JSON data from Input Parameter"></a></p><p>SQL Server 2016 introduced the support of JSON and added many new functions in the recent CTP3 version of SQL Server 2016.</p>
<blockquote><p>Now, we have OPENJSON() to extract JSON data into a tabular format. If you are passing JSON document as an input parameter in Stored Procedure, you can use OPENJSON() to extract the value of JSON parameter.</p></blockquote>
<blockquote class="wp-embedded-content" data-secret="dalsxXM11a"><p><a href="https://www.dbrnd.com/2016/12/sql-server-2016-introduced-json-support-to-store-and-retrieve-json-document-isjson-json_value-json_query/">SQL Server 2016: Introduced JSON support, to store and retrieve JSON document</a></p></blockquote>
<p><iframe class="wp-embedded-content" sandbox="allow-scripts" security="restricted"  src="https://www.dbrnd.com/2016/12/sql-server-2016-introduced-json-support-to-store-and-retrieve-json-document-isjson-json_value-json_query/embed/#?secret=dalsxXM11a" data-secret="dalsxXM11a" width="600" height="338" title="&#8220;SQL Server 2016: Introduced JSON support, to store and retrieve JSON document&#8221; &#8212; Database Research &amp; Development" frameborder="0" marginwidth="0" marginheight="0" scrolling="no"></iframe></p>
<p><strong>Please check the below sample use of OPENJSON():</strong></p>
<p><strong>Sample 1:</strong></p><pre class="crayon-plain-tag">DECLARE @SampleJson NVARCHAR(2000) = 
N'{
 "ID" : 1,
 "Name": "Anvesh",
 "Blog": "dbrnd.com",
 "DOB": "1988-01-26",
 "Position": "Database Engineer"
 }'
 GO

SELECT * FROM OPENJSON(@SampleJson)
GO</pre><p>
<img decoding="async" class="alignnone size-full wp-image-5639" src="https://www.dbrnd.com/wp-content/uploads/2017/07/OpenJSON.png" alt="SQL Open Json " width="205" height="123" /></p>
<p><strong>Sample 2:</strong></p><pre class="crayon-plain-tag">DECLARE @SampleJson NVARCHAR(2000) = 
N'[{
 "ID" : 8,
 "Name": "Anvesh",
 "Blog": "dbrnd.com",
 "DOB": "1988-01-26",
 "Position": "Database Engineer"
 }
 ,{
 "ID" : 10,
 "Name": "Roy",
 "Blog": "abc.com",
 "DOB": "1920-06-8",
 "Position": "Database Developer"
 }]'
 GO

 SELECT * FROM OPENJSON(@SampleJson)
 with
 (
	ID INT, 
	Name NVARCHAR(2000),
	Blog NVARCHAR(20),
	DOB DATE,
	Position NVARCHAR(20)
 )
 GO</pre><p>
<img loading="lazy" decoding="async" class="alignnone size-full wp-image-5640" src="https://www.dbrnd.com/wp-content/uploads/2017/07/OpenJSON2.png" alt="SQL Openjson()" width="340" height="71" /></p>
]]></content:encoded>
					
		
		
			</item>
		<item>
		<title>SQL Server 2016: Introduced JSON support, to store and retrieve JSON document</title>
		<link>https://www.dbrnd.com/2016/12/sql-server-2016-introduced-json-support-to-store-and-retrieve-json-document-isjson-json_value-json_query/</link>
					<comments>https://www.dbrnd.com/2016/12/sql-server-2016-introduced-json-support-to-store-and-retrieve-json-document-isjson-json_value-json_query/#comments</comments>
		
		<dc:creator><![CDATA[Anvesh Patel]]></dc:creator>
		<pubDate>Sat, 10 Dec 2016 19:51:08 +0000</pubDate>
				<category><![CDATA[SQL Server]]></category>
		<category><![CDATA[Anvesh Patel]]></category>
		<category><![CDATA[database]]></category>
		<category><![CDATA[database research and development]]></category>
		<category><![CDATA[dbrnd]]></category>
		<category><![CDATA[isjson]]></category>
		<category><![CDATA[JSON]]></category>
		<category><![CDATA[json_query]]></category>
		<category><![CDATA[json_value]]></category>
		<category><![CDATA[NoSQL]]></category>
		<category><![CDATA[SQL Query]]></category>
		<category><![CDATA[SQL Server Administrator]]></category>
		<category><![CDATA[SQL Server Monitoring]]></category>
		<category><![CDATA[SQL Server Performance Tunning]]></category>
		<category><![CDATA[SQL Server Tips and Tricks]]></category>
		<category><![CDATA[TSQL]]></category>
		<guid isPermaLink="false">https://www.dbrnd.com/?p=4025</guid>

					<description><![CDATA[JSON + RDBMS is one of the interesting topics, in the new version of SQL Server 2016 we can store JSON formatted data. Now a day JSON data type is a standard feature for all new coming RDBMS product versions like PostgreSQL 9.4, and MySQL 5.7 have already introduced this. Now We can say, we [&#8230;]]]></description>
										<content:encoded><![CDATA[<p><a class="a2a_button_facebook" href="https://www.addtoany.com/add_to/facebook?linkurl=https%3A%2F%2Fwww.dbrnd.com%2F2016%2F12%2Fsql-server-2016-introduced-json-support-to-store-and-retrieve-json-document-isjson-json_value-json_query%2F&amp;linkname=SQL%20Server%202016%3A%20Introduced%20JSON%20support%2C%20to%20store%20and%20retrieve%20JSON%20document" title="Facebook" rel="nofollow noopener" target="_blank"></a><a class="a2a_button_twitter" href="https://www.addtoany.com/add_to/twitter?linkurl=https%3A%2F%2Fwww.dbrnd.com%2F2016%2F12%2Fsql-server-2016-introduced-json-support-to-store-and-retrieve-json-document-isjson-json_value-json_query%2F&amp;linkname=SQL%20Server%202016%3A%20Introduced%20JSON%20support%2C%20to%20store%20and%20retrieve%20JSON%20document" title="Twitter" rel="nofollow noopener" target="_blank"></a><a class="a2a_button_linkedin" href="https://www.addtoany.com/add_to/linkedin?linkurl=https%3A%2F%2Fwww.dbrnd.com%2F2016%2F12%2Fsql-server-2016-introduced-json-support-to-store-and-retrieve-json-document-isjson-json_value-json_query%2F&amp;linkname=SQL%20Server%202016%3A%20Introduced%20JSON%20support%2C%20to%20store%20and%20retrieve%20JSON%20document" title="LinkedIn" rel="nofollow noopener" target="_blank"></a><a class="a2a_button_pinterest" href="https://www.addtoany.com/add_to/pinterest?linkurl=https%3A%2F%2Fwww.dbrnd.com%2F2016%2F12%2Fsql-server-2016-introduced-json-support-to-store-and-retrieve-json-document-isjson-json_value-json_query%2F&amp;linkname=SQL%20Server%202016%3A%20Introduced%20JSON%20support%2C%20to%20store%20and%20retrieve%20JSON%20document" title="Pinterest" rel="nofollow noopener" target="_blank"></a><a class="a2a_button_reddit" href="https://www.addtoany.com/add_to/reddit?linkurl=https%3A%2F%2Fwww.dbrnd.com%2F2016%2F12%2Fsql-server-2016-introduced-json-support-to-store-and-retrieve-json-document-isjson-json_value-json_query%2F&amp;linkname=SQL%20Server%202016%3A%20Introduced%20JSON%20support%2C%20to%20store%20and%20retrieve%20JSON%20document" title="Reddit" rel="nofollow noopener" target="_blank"></a><a class="a2a_button_pocket" href="https://www.addtoany.com/add_to/pocket?linkurl=https%3A%2F%2Fwww.dbrnd.com%2F2016%2F12%2Fsql-server-2016-introduced-json-support-to-store-and-retrieve-json-document-isjson-json_value-json_query%2F&amp;linkname=SQL%20Server%202016%3A%20Introduced%20JSON%20support%2C%20to%20store%20and%20retrieve%20JSON%20document" title="Pocket" rel="nofollow noopener" target="_blank"></a><a class="a2a_dd addtoany_share_save addtoany_share" href="https://www.addtoany.com/share#url=https%3A%2F%2Fwww.dbrnd.com%2F2016%2F12%2Fsql-server-2016-introduced-json-support-to-store-and-retrieve-json-document-isjson-json_value-json_query%2F&#038;title=SQL%20Server%202016%3A%20Introduced%20JSON%20support%2C%20to%20store%20and%20retrieve%20JSON%20document" data-a2a-url="https://www.dbrnd.com/2016/12/sql-server-2016-introduced-json-support-to-store-and-retrieve-json-document-isjson-json_value-json_query/" data-a2a-title="SQL Server 2016: Introduced JSON support, to store and retrieve JSON document"></a></p><p>JSON + RDBMS is one of the interesting topics, in the new version of SQL Server 2016 we can store JSON formatted data.</p>
<p>Now a day JSON data type is a standard feature for all new coming RDBMS product versions like PostgreSQL 9.4, and MySQL 5.7 have already introduced this.</p>
<blockquote><p>Now We can say, we have SQL Server 2016 with the RDBMS + NoSQL concepts.<br />
We can store JSON data as nvarchar, but the JSON related functions have the advantage of enforcing that each stored value is valid according to the JSON rules.</p></blockquote>
<p><strong>Small demonstration on SQL Server 2016 JSON:</strong></p>
<p><strong>Create a sample table and define two column as NVARCHAR to store JSON data:</strong></p><pre class="crayon-plain-tag">CREATE TABLE tbl_TestSQLJSON
(
	ID INTEGER PRIMARY KEY
	,DepartmentName VARCHAR(250)
	,EmployeeName NVARCHAR(MAX)
	,EmployeeAddress NVARCHAR(MAX)
)
GO</pre><p> </p>
<p>Use ISJSON() and add check constraint in json columns:<br />
If your json format and document is correct, It returns true other It returns false.</p><pre class="crayon-plain-tag">ALTER TABLE tbl_TestSQLJSON
ADD CONSTRAINT ck_tbl_TestSQLJSON_EmployeeName
CHECK (ISJSON( EmployeeName ) &gt; 0)
GO

ALTER TABLE tbl_TestSQLJSON
ADD CONSTRAINT ck_tbl_TestSQLJSON_EmployeeAddress
CHECK (ISJSON( EmployeeAddress ) &gt; 0)
GO</pre><p> </p>
<p>Insert few sample JSON data:</p><pre class="crayon-plain-tag">INSERT INTO tbl_TestSQLJSON
VALUES 
(
	1
	,'Sales'
	,N'{"firstName": "Anvesh", "lastName": "Patel"}'
	,N'
	{"address" : 
		{ 
			"India": "Hyderabad"
			,"USA": "Newyork"
		}
	}'
)
,(
	2
	,'Production'
	,N'{"firstName": "Neevan", "lastName": "Patel"}'
	,N'
	{"address" : 
		{ 
			"India": "Ahmedabad"
			,"USA": "Washington DC"
		}
	}'
)
,(
	3
	,'Animation'
	,N'{"firstName": "Eric", "lastName": "Lorn"}'
	,N'
	{"address" : 
		{ 
			"India": "Mumbai"
			,"USA": "Chicago"
		}
	}'
)
GO</pre><p> </p>
<p><strong>SELECT json data:</strong></p><pre class="crayon-plain-tag">SELECT 
	ID
	,DepartmentName
	,JSON_VALUE(EmployeeName, '$.firstName') AS EmployeeFirstName     
	,JSON_VALUE(EmployeeAddress, '$.address.India') AS AddressIndia
	,JSON_VALUE(EmployeeAddress, '$.address.USA') AS AddressUSA
	,JSON_QUERY(EmployeeAddress, '$.address') AS EmployeeAddressJSON
FROM tbl_TestSQLJSON
GO</pre><p> </p>
<p><strong>Use JSON_VALUE() in WHERE Clause:</strong></p><pre class="crayon-plain-tag">SELECT 
	ID
	,DepartmentName
	,JSON_VALUE(EmployeeName, '$.firstName') AS EmployeeFirstName     	
FROM tbl_TestSQLJSON
WHERE JSON_VALUE(EmployeeName, '$.firstName') = 'Anvesh'
GO</pre><p> </p>
]]></content:encoded>
					
					<wfw:commentRss>https://www.dbrnd.com/2016/12/sql-server-2016-introduced-json-support-to-store-and-retrieve-json-document-isjson-json_value-json_query/feed/</wfw:commentRss>
			<slash:comments>1</slash:comments>
		
		
			</item>
		<item>
		<title>MySQL 5.7: How to create an Index on JSON Data Type Column</title>
		<link>https://www.dbrnd.com/2016/10/mysql-5-7-how-to-create-an-index-on-json-data-type-column-generated-virtual-column/</link>
		
		<dc:creator><![CDATA[Anvesh Patel]]></dc:creator>
		<pubDate>Thu, 13 Oct 2016 16:16:24 +0000</pubDate>
				<category><![CDATA[MySQL]]></category>
		<category><![CDATA[Anvesh Patel]]></category>
		<category><![CDATA[database]]></category>
		<category><![CDATA[database research and development]]></category>
		<category><![CDATA[dbrnd]]></category>
		<category><![CDATA[generated column]]></category>
		<category><![CDATA[index]]></category>
		<category><![CDATA[JSON]]></category>
		<category><![CDATA[JSON Data Type]]></category>
		<category><![CDATA[MySQL 5.7]]></category>
		<category><![CDATA[MySQL Command]]></category>
		<category><![CDATA[MySQL Database Administrator]]></category>
		<category><![CDATA[MySQL Database Designing]]></category>
		<category><![CDATA[MySQL Database Programming]]></category>
		<category><![CDATA[MySQL Error]]></category>
		<category><![CDATA[MySQL Performance Tunning]]></category>
		<category><![CDATA[MySQL Query]]></category>
		<category><![CDATA[MySQL Tips and Tricks]]></category>
		<category><![CDATA[virtual column]]></category>
		<guid isPermaLink="false">https://www.dbrnd.com/?p=3729</guid>

					<description><![CDATA[In the previous two articles, I have shared basic detail about MySQL 5.7 JSON Data Type. Our next question is, How we can create an Index on JSON Data Type in MySQL 5.7. As per the official document, actually we cannot directly create an Index on JSON column in MySQL. We have to add generated [&#8230;]]]></description>
										<content:encoded><![CDATA[<p><a class="a2a_button_facebook" href="https://www.addtoany.com/add_to/facebook?linkurl=https%3A%2F%2Fwww.dbrnd.com%2F2016%2F10%2Fmysql-5-7-how-to-create-an-index-on-json-data-type-column-generated-virtual-column%2F&amp;linkname=MySQL%205.7%3A%20How%20to%20create%20an%20Index%20on%20JSON%20Data%20Type%20Column" title="Facebook" rel="nofollow noopener" target="_blank"></a><a class="a2a_button_twitter" href="https://www.addtoany.com/add_to/twitter?linkurl=https%3A%2F%2Fwww.dbrnd.com%2F2016%2F10%2Fmysql-5-7-how-to-create-an-index-on-json-data-type-column-generated-virtual-column%2F&amp;linkname=MySQL%205.7%3A%20How%20to%20create%20an%20Index%20on%20JSON%20Data%20Type%20Column" title="Twitter" rel="nofollow noopener" target="_blank"></a><a class="a2a_button_linkedin" href="https://www.addtoany.com/add_to/linkedin?linkurl=https%3A%2F%2Fwww.dbrnd.com%2F2016%2F10%2Fmysql-5-7-how-to-create-an-index-on-json-data-type-column-generated-virtual-column%2F&amp;linkname=MySQL%205.7%3A%20How%20to%20create%20an%20Index%20on%20JSON%20Data%20Type%20Column" title="LinkedIn" rel="nofollow noopener" target="_blank"></a><a class="a2a_button_pinterest" href="https://www.addtoany.com/add_to/pinterest?linkurl=https%3A%2F%2Fwww.dbrnd.com%2F2016%2F10%2Fmysql-5-7-how-to-create-an-index-on-json-data-type-column-generated-virtual-column%2F&amp;linkname=MySQL%205.7%3A%20How%20to%20create%20an%20Index%20on%20JSON%20Data%20Type%20Column" title="Pinterest" rel="nofollow noopener" target="_blank"></a><a class="a2a_button_reddit" href="https://www.addtoany.com/add_to/reddit?linkurl=https%3A%2F%2Fwww.dbrnd.com%2F2016%2F10%2Fmysql-5-7-how-to-create-an-index-on-json-data-type-column-generated-virtual-column%2F&amp;linkname=MySQL%205.7%3A%20How%20to%20create%20an%20Index%20on%20JSON%20Data%20Type%20Column" title="Reddit" rel="nofollow noopener" target="_blank"></a><a class="a2a_button_pocket" href="https://www.addtoany.com/add_to/pocket?linkurl=https%3A%2F%2Fwww.dbrnd.com%2F2016%2F10%2Fmysql-5-7-how-to-create-an-index-on-json-data-type-column-generated-virtual-column%2F&amp;linkname=MySQL%205.7%3A%20How%20to%20create%20an%20Index%20on%20JSON%20Data%20Type%20Column" title="Pocket" rel="nofollow noopener" target="_blank"></a><a class="a2a_dd addtoany_share_save addtoany_share" href="https://www.addtoany.com/share#url=https%3A%2F%2Fwww.dbrnd.com%2F2016%2F10%2Fmysql-5-7-how-to-create-an-index-on-json-data-type-column-generated-virtual-column%2F&#038;title=MySQL%205.7%3A%20How%20to%20create%20an%20Index%20on%20JSON%20Data%20Type%20Column" data-a2a-url="https://www.dbrnd.com/2016/10/mysql-5-7-how-to-create-an-index-on-json-data-type-column-generated-virtual-column/" data-a2a-title="MySQL 5.7: How to create an Index on JSON Data Type Column"></a></p><p>In the previous two articles, I have shared basic detail about MySQL 5.7 JSON Data Type.<br />
Our next question is, How we can create an Index on JSON Data Type in MySQL 5.7.</p>
<p><a href="https://dev.mysql.com/doc/refman/5.7/en/create-table-secondary-indexes-virtual-columns.html" target="_blank">As per the official document,</a> actually we cannot directly create an Index on JSON column in MySQL.</p>
<blockquote><p>We have to add generated column in Table by extracting require JSON Key data.<br />
Once require JSON key data extracted, we can apply index on that column like any other column. </p></blockquote>
<p>Actually, this is not a good way, but as of now we have only this option to create an indirect Index on JSON Column in MySQL 5.7.</p>
<p><strong>Create sample table using JSON data type:</strong></p>
<pre class="crayon-plain-tag">CREATE TABLE tbl_TestJSON
(
	ID INTEGER PRIMARY KEY
	,DepartName VARCHAR(250)
	,EmployeeDetails JSON
	,Address JSON
);</pre> </p>
<p><strong>Insert few sample JSON formatted record: </strong></p>
<pre class="crayon-plain-tag">INSERT INTO tbl_TestJSON
VALUES 
(
	1
	,'Sales'
	,'{"firstName": "Anvesh", "lastName": "Patel"}'
	,'
	{"address" : 
		{ 
			"India": "Hyderabad"
			,"USA": "Newyork"
		}
	}'
)
,(
	2
	,'Production'
	,'{"firstName": "Neevan", "lastName": "Patel"}'
	,'
	{"address" : 
		{ 
			"India": "Ahmedabad"
			,"USA": "Washington DC"
		}
	}'
)
,(
	3
	,'Animation'
	,'{"firstName": "Eric", "lastName": "Lorn"}'
	,'
	{"address" : 
		{ 
			"India": "Mumbai"
			,"USA": "Chicago"
		}
	}'
);</pre> </p>
<p><strong>Create aditional generated column for JSON Field EmployeeDetails->firstName:</strong></p>
<pre class="crayon-plain-tag">ALTER TABLE tbl_TestJSON ADD VirtualColumn VARCHAR(50) 
GENERATED ALWAYS AS (JSON_EXTRACT(EmployeeDetails, '$.firstName')) VIRTUAL;</pre> </p>
<p><strong>Create Index on generated column which indirectly work as Index on JSON EmployeeDetails->firstName:</strong></p>
<pre class="crayon-plain-tag">CREATE INDEX idx_tbl_TestJSON_VirtualColumn ON tbl_TestJSON(VirtualColumn);</pre> </p>
<p><strong>Check the execution plan of below query, where you can find usage of newly created Index:</strong></p>
<pre class="crayon-plain-tag">EXPLAIN
SELECT JSON_EXTRACT(EmployeeDetails, "$.firstName") 
FROM tbl_TestJSON 
WHERE VirtualColumn = 'Anvesh';</pre> </p>
]]></content:encoded>
					
		
		
			</item>
		<item>
		<title>MySQL 5.7: Introduced JSON Functions for Search and Manipulation</title>
		<link>https://www.dbrnd.com/2016/10/mysql-5-7-introduced-json-functions-for-search-and-manipulation-json_extract-json_search-json_length-json_array_append/</link>
		
		<dc:creator><![CDATA[Anvesh Patel]]></dc:creator>
		<pubDate>Wed, 12 Oct 2016 16:18:22 +0000</pubDate>
				<category><![CDATA[MySQL]]></category>
		<category><![CDATA[Anvesh Patel]]></category>
		<category><![CDATA[database]]></category>
		<category><![CDATA[database research and development]]></category>
		<category><![CDATA[dbrnd]]></category>
		<category><![CDATA[JSON]]></category>
		<category><![CDATA[JSON_EXTRACT]]></category>
		<category><![CDATA[JSON_KEYS]]></category>
		<category><![CDATA[JSON_LENGTH]]></category>
		<category><![CDATA[JSON_MERGE]]></category>
		<category><![CDATA[JSON_SEARCH]]></category>
		<category><![CDATA[JSON_TYPE]]></category>
		<category><![CDATA[MySQL 5.7]]></category>
		<category><![CDATA[MySQL Command]]></category>
		<category><![CDATA[MySQL Database Administrator]]></category>
		<category><![CDATA[MySQL Database Designing]]></category>
		<category><![CDATA[MySQL Database Programming]]></category>
		<category><![CDATA[MySQL Error]]></category>
		<category><![CDATA[MySQL Performance Tunning]]></category>
		<category><![CDATA[MySQL Query]]></category>
		<category><![CDATA[MySQL Tips and Tricks]]></category>
		<guid isPermaLink="false">https://www.dbrnd.com/?p=3726</guid>

					<description><![CDATA[In the previous article, I have shared basic about MySQL 5.7 new JSON Data Type. MySQL 5.7 also introduced different types of JSON related function. In this post, I am sharing a few of those important JSON function. First, create a sample table with JSON data type: [crayon-6ab4922c0a284672944516/] Insert few valid JSON Data: [crayon-6ab4922c0a285970981693/] JSON_EXTRACT(): [&#8230;]]]></description>
										<content:encoded><![CDATA[<p><a class="a2a_button_facebook" href="https://www.addtoany.com/add_to/facebook?linkurl=https%3A%2F%2Fwww.dbrnd.com%2F2016%2F10%2Fmysql-5-7-introduced-json-functions-for-search-and-manipulation-json_extract-json_search-json_length-json_array_append%2F&amp;linkname=MySQL%205.7%3A%20Introduced%20JSON%20Functions%20for%20Search%20and%20Manipulation" title="Facebook" rel="nofollow noopener" target="_blank"></a><a class="a2a_button_twitter" href="https://www.addtoany.com/add_to/twitter?linkurl=https%3A%2F%2Fwww.dbrnd.com%2F2016%2F10%2Fmysql-5-7-introduced-json-functions-for-search-and-manipulation-json_extract-json_search-json_length-json_array_append%2F&amp;linkname=MySQL%205.7%3A%20Introduced%20JSON%20Functions%20for%20Search%20and%20Manipulation" title="Twitter" rel="nofollow noopener" target="_blank"></a><a class="a2a_button_linkedin" href="https://www.addtoany.com/add_to/linkedin?linkurl=https%3A%2F%2Fwww.dbrnd.com%2F2016%2F10%2Fmysql-5-7-introduced-json-functions-for-search-and-manipulation-json_extract-json_search-json_length-json_array_append%2F&amp;linkname=MySQL%205.7%3A%20Introduced%20JSON%20Functions%20for%20Search%20and%20Manipulation" title="LinkedIn" rel="nofollow noopener" target="_blank"></a><a class="a2a_button_pinterest" href="https://www.addtoany.com/add_to/pinterest?linkurl=https%3A%2F%2Fwww.dbrnd.com%2F2016%2F10%2Fmysql-5-7-introduced-json-functions-for-search-and-manipulation-json_extract-json_search-json_length-json_array_append%2F&amp;linkname=MySQL%205.7%3A%20Introduced%20JSON%20Functions%20for%20Search%20and%20Manipulation" title="Pinterest" rel="nofollow noopener" target="_blank"></a><a class="a2a_button_reddit" href="https://www.addtoany.com/add_to/reddit?linkurl=https%3A%2F%2Fwww.dbrnd.com%2F2016%2F10%2Fmysql-5-7-introduced-json-functions-for-search-and-manipulation-json_extract-json_search-json_length-json_array_append%2F&amp;linkname=MySQL%205.7%3A%20Introduced%20JSON%20Functions%20for%20Search%20and%20Manipulation" title="Reddit" rel="nofollow noopener" target="_blank"></a><a class="a2a_button_pocket" href="https://www.addtoany.com/add_to/pocket?linkurl=https%3A%2F%2Fwww.dbrnd.com%2F2016%2F10%2Fmysql-5-7-introduced-json-functions-for-search-and-manipulation-json_extract-json_search-json_length-json_array_append%2F&amp;linkname=MySQL%205.7%3A%20Introduced%20JSON%20Functions%20for%20Search%20and%20Manipulation" title="Pocket" rel="nofollow noopener" target="_blank"></a><a class="a2a_dd addtoany_share_save addtoany_share" href="https://www.addtoany.com/share#url=https%3A%2F%2Fwww.dbrnd.com%2F2016%2F10%2Fmysql-5-7-introduced-json-functions-for-search-and-manipulation-json_extract-json_search-json_length-json_array_append%2F&#038;title=MySQL%205.7%3A%20Introduced%20JSON%20Functions%20for%20Search%20and%20Manipulation" data-a2a-url="https://www.dbrnd.com/2016/10/mysql-5-7-introduced-json-functions-for-search-and-manipulation-json_extract-json_search-json_length-json_array_append/" data-a2a-title="MySQL 5.7: Introduced JSON Functions for Search and Manipulation"></a></p><p>In the previous article, I have shared basic about MySQL 5.7 new JSON Data Type.<br />
MySQL 5.7 also introduced different types of JSON related function.<br />
In this post, I am sharing a few of those important JSON function.</p>
<p><strong>First, create a sample table with JSON data type:</strong></p>
<pre class="crayon-plain-tag">CREATE TABLE tbl_TestJSON
(
	ID INTEGER PRIMARY KEY
	,DepartName VARCHAR(250)
	,EmployeeDetails JSON
	,Address JSON
);</pre> </p>
<p><strong>Insert few valid JSON Data: </strong></p>
<pre class="crayon-plain-tag">INSERT INTO tbl_TestJSON
VALUES 
(
	1
	,'Sales'
	,'{"firstName": "Anvesh", "lastName": "Patel"}'
	,'
	{"address" : 
		{ 
			"India": "Hyderabad"
			,"USA": "Newyork"
		}
	}'
)
,(
	2
	,'Production'
	,'{"firstName": "Neevan", "lastName": "Patel"}'
	,'
	{"address" : 
		{ 
			"India": "Ahmedabad"
			,"USA": "Washington DC"
		}
	}'
)
,(
	3
	,'Animation'
	,'{"firstName": "Eric", "lastName": "Lorn"}'
	,'
	{"address" : 
		{ 
			"India": "Mumbai"
			,"USA": "Chicago"
		}
	}'
);</pre> </p>
<p><strong>JSON_EXTRACT(): To extract or search value in JSON.</strong></p>
<pre class="crayon-plain-tag">SELECT JSON_EXTRACT(Address, "$.address.*") FROM tbl_TestJSON;
+--------------------------------------+
| JSON_EXTRACT(Address, "$.address.*") |
+--------------------------------------+
| ["Newyork", "Hyderabad"]             |
| ["Washington DC", "Ahmedabad"]       |
| ["Chicago", "Mumbai"]                |
+--------------------------------------+

SELECT JSON_EXTRACT(Address, "$.address.India") FROM tbl_TestJSON;
+------------------------------------------+
| JSON_EXTRACT(Address, "$.address.India") |
+------------------------------------------+
| "Hyderabad"                              |
| "Ahmedabad"                              |
| "Mumbai"                                 |
+------------------------------------------+

 SELECT JSON_EXTRACT(Address, "$**.USA") FROM tbl_TestJSON;
+----------------------------------+
| JSON_EXTRACT(Address, "$**.USA") |
+----------------------------------+
| ["Newyork"]                      |
| ["Washington DC"]                |
| ["Chicago"]                      |
+----------------------------------+</pre> </p>
<p><strong>JSON_SEARCH(): Use to search key value path.</strong><br />
one: The search terminates after the first match and returns one path string<br />
all: The search returns all matching path strings such that no duplicate paths are included.</p>
<pre class="crayon-plain-tag">SELECT JSON_SEARCH(Address,'one','Mumbai') FROM tbl_TestJSON; 
SELECT JSON_SEARCH(Address,'all','Mumbai') FROM tbl_TestJSON;</pre> </p>
<p><strong>JSON_LENGTH():Use to check length of JSON document.</strong></p>
<pre class="crayon-plain-tag">SELECT JSON_LENGTH (EmployeeDetails) FROM tbl_TestJSON;</pre> </p>
<p><strong>JSON_TYPE(): Use to check type of JSON document.</strong></p>
<pre class="crayon-plain-tag">SELECT JSON_TYPE (EmployeeDetails) FROM tbl_TestJSON;</pre> </p>
<p><strong>JSON_KEYS(): Use to fetch list of JSON keys.</strong></p>
<pre class="crayon-plain-tag">SELECT JSON_KEYS (EmployeeDetails) FROM tbl_TestJSON;</pre> </p>
<p><strong>JSON_MERGE(): Use to merge JSON data.</strong></p>
<pre class="crayon-plain-tag">SELECT JSON_MERGE('["Anvesh", 1]', '{"Name": "Anvesh"}');
+---------------------------------------------------+
| JSON_MERGE('["Anvesh", 1]', '{"Name": "Anvesh"}') |
+---------------------------------------------------+
| ["Anvesh", 1, {"Name": "Anvesh"}]                 |
+---------------------------------------------------+</pre> </p>
<p><strong>JSON_ARRAY_APPEND(): Use to append any data into JSON document.</strong></p>
<pre class="crayon-plain-tag">SELECT JSON_ARRAY_APPEND('["a", ["b", "c"], "d"]','$[1]','e');
+--------------------------------------------------------+
| JSON_ARRAY_APPEND('["a", ["b", "c"], "d"]','$[1]','e') |
+--------------------------------------------------------+
| ["a", ["b", "c", "e"], "d"]                            |
+--------------------------------------------------------+

SELECT JSON_ARRAY_APPEND('["a", ["b", "c"], "d"]','$[0]','g');
+--------------------------------------------------------+
| JSON_ARRAY_APPEND('["a", ["b", "c"], "d"]','$[0]','g') |
+--------------------------------------------------------+
| [["a", "g"], ["b", "c"], "d"]                          |
+--------------------------------------------------------+</pre> </p>
]]></content:encoded>
					
		
		
			</item>
		<item>
		<title>MySQL 5.7: Introduced Awesome JSON Data Type</title>
		<link>https://www.dbrnd.com/2016/10/mysql-5-7-introduced-awesome-json-data-type-nosql-advantage-in-rdbms-system/</link>
		
		<dc:creator><![CDATA[Anvesh Patel]]></dc:creator>
		<pubDate>Tue, 11 Oct 2016 16:16:19 +0000</pubDate>
				<category><![CDATA[MySQL]]></category>
		<category><![CDATA[Anvesh Patel]]></category>
		<category><![CDATA[database]]></category>
		<category><![CDATA[database research and development]]></category>
		<category><![CDATA[dbrnd]]></category>
		<category><![CDATA[JSON]]></category>
		<category><![CDATA[JSON Data Type]]></category>
		<category><![CDATA[MySQL 5.7]]></category>
		<category><![CDATA[MySQL Command]]></category>
		<category><![CDATA[MySQL Database Administrator]]></category>
		<category><![CDATA[MySQL Database Designing]]></category>
		<category><![CDATA[MySQL Database Programming]]></category>
		<category><![CDATA[MySQL Error]]></category>
		<category><![CDATA[MySQL Performance Tunning]]></category>
		<category><![CDATA[MySQL Query]]></category>
		<category><![CDATA[MySQL Tips and Tricks]]></category>
		<category><![CDATA[NoSQL]]></category>
		<guid isPermaLink="false">https://www.dbrnd.com/?p=3724</guid>

					<description><![CDATA[This is one of the interesting topics, in the new version of MySQL 5.7 we can store JSON formatted data. Now a day JSON data type is a common feature for all new coming RDBMS product versions like: PostgreSQL 9.4 and SQL Server 2016 have already introduced this. Now We can say, we have MySQL [&#8230;]]]></description>
										<content:encoded><![CDATA[<p><a class="a2a_button_facebook" href="https://www.addtoany.com/add_to/facebook?linkurl=https%3A%2F%2Fwww.dbrnd.com%2F2016%2F10%2Fmysql-5-7-introduced-awesome-json-data-type-nosql-advantage-in-rdbms-system%2F&amp;linkname=MySQL%205.7%3A%20Introduced%20Awesome%20JSON%20Data%20Type" title="Facebook" rel="nofollow noopener" target="_blank"></a><a class="a2a_button_twitter" href="https://www.addtoany.com/add_to/twitter?linkurl=https%3A%2F%2Fwww.dbrnd.com%2F2016%2F10%2Fmysql-5-7-introduced-awesome-json-data-type-nosql-advantage-in-rdbms-system%2F&amp;linkname=MySQL%205.7%3A%20Introduced%20Awesome%20JSON%20Data%20Type" title="Twitter" rel="nofollow noopener" target="_blank"></a><a class="a2a_button_linkedin" href="https://www.addtoany.com/add_to/linkedin?linkurl=https%3A%2F%2Fwww.dbrnd.com%2F2016%2F10%2Fmysql-5-7-introduced-awesome-json-data-type-nosql-advantage-in-rdbms-system%2F&amp;linkname=MySQL%205.7%3A%20Introduced%20Awesome%20JSON%20Data%20Type" title="LinkedIn" rel="nofollow noopener" target="_blank"></a><a class="a2a_button_pinterest" href="https://www.addtoany.com/add_to/pinterest?linkurl=https%3A%2F%2Fwww.dbrnd.com%2F2016%2F10%2Fmysql-5-7-introduced-awesome-json-data-type-nosql-advantage-in-rdbms-system%2F&amp;linkname=MySQL%205.7%3A%20Introduced%20Awesome%20JSON%20Data%20Type" title="Pinterest" rel="nofollow noopener" target="_blank"></a><a class="a2a_button_reddit" href="https://www.addtoany.com/add_to/reddit?linkurl=https%3A%2F%2Fwww.dbrnd.com%2F2016%2F10%2Fmysql-5-7-introduced-awesome-json-data-type-nosql-advantage-in-rdbms-system%2F&amp;linkname=MySQL%205.7%3A%20Introduced%20Awesome%20JSON%20Data%20Type" title="Reddit" rel="nofollow noopener" target="_blank"></a><a class="a2a_button_pocket" href="https://www.addtoany.com/add_to/pocket?linkurl=https%3A%2F%2Fwww.dbrnd.com%2F2016%2F10%2Fmysql-5-7-introduced-awesome-json-data-type-nosql-advantage-in-rdbms-system%2F&amp;linkname=MySQL%205.7%3A%20Introduced%20Awesome%20JSON%20Data%20Type" title="Pocket" rel="nofollow noopener" target="_blank"></a><a class="a2a_dd addtoany_share_save addtoany_share" href="https://www.addtoany.com/share#url=https%3A%2F%2Fwww.dbrnd.com%2F2016%2F10%2Fmysql-5-7-introduced-awesome-json-data-type-nosql-advantage-in-rdbms-system%2F&#038;title=MySQL%205.7%3A%20Introduced%20Awesome%20JSON%20Data%20Type" data-a2a-url="https://www.dbrnd.com/2016/10/mysql-5-7-introduced-awesome-json-data-type-nosql-advantage-in-rdbms-system/" data-a2a-title="MySQL 5.7: Introduced Awesome JSON Data Type"></a></p><p>This is one of the interesting topics, in the new version of MySQL 5.7 we can store JSON formatted data.<br />
Now a day JSON data type is a common feature for all new coming RDBMS product versions like: PostgreSQL 9.4 and SQL Server 2016 have already introduced this. </p>
<blockquote><p>Now We can say, we have MySQL 5.7 with the RDBMS + NOSQL concepts.</p></blockquote>
<blockquote><p>We can store JSON data as strings, but the JSON Data types have the advantage of enforcing that each stored value is valid according to the JSON rules.</p></blockquote>
<blockquote><p>The size of JSON documents stored in JSON columns is limited to the value of the max_allowed_packet system variable.</p></blockquote>
<blockquote><p>The JSON columns cannot have a default value.</p></blockquote>
<p>MySQL 5.7 also introduced a different function to manipulate and manage JSON data in MySQL.<br />
Tomorrow, I will demonstrate these functions. </p>
<p><strong>Small demonstration JSON Data Type:</strong><br />
<strong>Create table with JSON Data type:</strong></p>
<pre class="crayon-plain-tag">CREATE TABLE tbl_TestJSON
(
	ID INTEGER PRIMARY KEY
	,DepartName VARCHAR(250)
	,EmployeeDetails JSON
	,Address JSON
);</pre> </p>
<p><strong>Insert few sample record:</strong></p>
<pre class="crayon-plain-tag">INSERT INTO tbl_TestJSON
VALUES 
(
	1
	,'Sales'
	,'{"firstName": "Anvesh", "lastName": "Patel"}'
	,'{"address" : "Hyderabad"}'
)
,(
	2
	,'Production'
	,'{"firstName": "Neevan", "lastName": "Patel"}'
	,'{"address" : "Ahmedabad"}'
)
,(
	3
	,'Animation'
	,'{"firstName": "Eric", "lastName": "Lorn"}'
	,'{"address" : "USA"}'
);</pre> </p>
<p><strong>You can search key value in WHERE clause:</strong></p>
<pre class="crayon-plain-tag">SELECT *FROM tbl_TestJSON 
WHERE EmployeeDetails-&gt;"$.firstName"="Neevan";</pre> </p>
]]></content:encoded>
					
		
		
			</item>
		<item>
		<title>PostgreSQL 9.4: How to Convert JSON ARRAY Elements into String ARRAY</title>
		<link>https://www.dbrnd.com/2016/08/postgresql-9-4-how-to-convert-json-array-elements-into-string-array-jsonb_array_elements-string_agg/</link>
		
		<dc:creator><![CDATA[Anvesh Patel]]></dc:creator>
		<pubDate>Sun, 28 Aug 2016 17:45:59 +0000</pubDate>
				<category><![CDATA[PostgreSQL]]></category>
		<category><![CDATA[Anvesh Patel]]></category>
		<category><![CDATA[database]]></category>
		<category><![CDATA[database research and development]]></category>
		<category><![CDATA[dbrnd]]></category>
		<category><![CDATA[JSON]]></category>
		<category><![CDATA[json array]]></category>
		<category><![CDATA[jsonb_array_elements]]></category>
		<category><![CDATA[plpgsql]]></category>
		<category><![CDATA[Postgres Query]]></category>
		<category><![CDATA[postgresql]]></category>
		<category><![CDATA[PostgreSQL 9.4]]></category>
		<category><![CDATA[PostgreSQL Administrator]]></category>
		<category><![CDATA[PostgreSQL Error]]></category>
		<category><![CDATA[PostgreSQL Programming]]></category>
		<category><![CDATA[PostgreSQL Tips and Tricks]]></category>
		<category><![CDATA[string array]]></category>
		<category><![CDATA[string_agg]]></category>
		<guid isPermaLink="false">https://www.dbrnd.com/?p=3508</guid>

					<description><![CDATA[I have already written a couple of articles about the PostgreSQL JSON Data type and its different type of operations. PostgreSQL 9.4: The JSON data type is Awesome (Part 1/3) PostgreSQL: How to convert Table Data into JSON formatted Data? In this post, I am going to share one more demonstration about PostgreSQL JSON. In [&#8230;]]]></description>
										<content:encoded><![CDATA[<p><a class="a2a_button_facebook" href="https://www.addtoany.com/add_to/facebook?linkurl=https%3A%2F%2Fwww.dbrnd.com%2F2016%2F08%2Fpostgresql-9-4-how-to-convert-json-array-elements-into-string-array-jsonb_array_elements-string_agg%2F&amp;linkname=PostgreSQL%209.4%3A%20How%20to%20Convert%20JSON%20ARRAY%20Elements%20into%20String%20ARRAY" title="Facebook" rel="nofollow noopener" target="_blank"></a><a class="a2a_button_twitter" href="https://www.addtoany.com/add_to/twitter?linkurl=https%3A%2F%2Fwww.dbrnd.com%2F2016%2F08%2Fpostgresql-9-4-how-to-convert-json-array-elements-into-string-array-jsonb_array_elements-string_agg%2F&amp;linkname=PostgreSQL%209.4%3A%20How%20to%20Convert%20JSON%20ARRAY%20Elements%20into%20String%20ARRAY" title="Twitter" rel="nofollow noopener" target="_blank"></a><a class="a2a_button_linkedin" href="https://www.addtoany.com/add_to/linkedin?linkurl=https%3A%2F%2Fwww.dbrnd.com%2F2016%2F08%2Fpostgresql-9-4-how-to-convert-json-array-elements-into-string-array-jsonb_array_elements-string_agg%2F&amp;linkname=PostgreSQL%209.4%3A%20How%20to%20Convert%20JSON%20ARRAY%20Elements%20into%20String%20ARRAY" title="LinkedIn" rel="nofollow noopener" target="_blank"></a><a class="a2a_button_pinterest" href="https://www.addtoany.com/add_to/pinterest?linkurl=https%3A%2F%2Fwww.dbrnd.com%2F2016%2F08%2Fpostgresql-9-4-how-to-convert-json-array-elements-into-string-array-jsonb_array_elements-string_agg%2F&amp;linkname=PostgreSQL%209.4%3A%20How%20to%20Convert%20JSON%20ARRAY%20Elements%20into%20String%20ARRAY" title="Pinterest" rel="nofollow noopener" target="_blank"></a><a class="a2a_button_reddit" href="https://www.addtoany.com/add_to/reddit?linkurl=https%3A%2F%2Fwww.dbrnd.com%2F2016%2F08%2Fpostgresql-9-4-how-to-convert-json-array-elements-into-string-array-jsonb_array_elements-string_agg%2F&amp;linkname=PostgreSQL%209.4%3A%20How%20to%20Convert%20JSON%20ARRAY%20Elements%20into%20String%20ARRAY" title="Reddit" rel="nofollow noopener" target="_blank"></a><a class="a2a_button_pocket" href="https://www.addtoany.com/add_to/pocket?linkurl=https%3A%2F%2Fwww.dbrnd.com%2F2016%2F08%2Fpostgresql-9-4-how-to-convert-json-array-elements-into-string-array-jsonb_array_elements-string_agg%2F&amp;linkname=PostgreSQL%209.4%3A%20How%20to%20Convert%20JSON%20ARRAY%20Elements%20into%20String%20ARRAY" title="Pocket" rel="nofollow noopener" target="_blank"></a><a class="a2a_dd addtoany_share_save addtoany_share" href="https://www.addtoany.com/share#url=https%3A%2F%2Fwww.dbrnd.com%2F2016%2F08%2Fpostgresql-9-4-how-to-convert-json-array-elements-into-string-array-jsonb_array_elements-string_agg%2F&#038;title=PostgreSQL%209.4%3A%20How%20to%20Convert%20JSON%20ARRAY%20Elements%20into%20String%20ARRAY" data-a2a-url="https://www.dbrnd.com/2016/08/postgresql-9-4-how-to-convert-json-array-elements-into-string-array-jsonb_array_elements-string_agg/" data-a2a-title="PostgreSQL 9.4: How to Convert JSON ARRAY Elements into String ARRAY"></a></p><p>I have already written a couple of articles about the PostgreSQL JSON Data type and its different type of operations. </p>
<blockquote class="wp-embedded-content" data-secret="yHkJmiNw3k"><p><a href="https://www.dbrnd.com/2016/02/postgresql-9-4-the-json-data-type-is-awesome-part-1/">PostgreSQL 9.4: The JSON data type is Awesome (Part 1/3)</a></p></blockquote>
<p><iframe loading="lazy" class="wp-embedded-content" sandbox="allow-scripts" security="restricted"  src="https://www.dbrnd.com/2016/02/postgresql-9-4-the-json-data-type-is-awesome-part-1/embed/#?secret=yHkJmiNw3k" data-secret="yHkJmiNw3k" width="600" height="338" title="&#8220;PostgreSQL 9.4: The JSON data type is Awesome (Part 1/3)&#8221; &#8212; Database Research &amp; Development" frameborder="0" marginwidth="0" marginheight="0" scrolling="no"></iframe></p>
<blockquote class="wp-embedded-content" data-secret="VD7ESsiJeP"><p><a href="https://www.dbrnd.com/2016/08/postgresql-how-to-convert-table-data-record-into-json-formatted-document-data/">PostgreSQL: How to convert Table Data into JSON formatted Data?</a></p></blockquote>
<p><iframe loading="lazy" class="wp-embedded-content" sandbox="allow-scripts" security="restricted"  src="https://www.dbrnd.com/2016/08/postgresql-how-to-convert-table-data-record-into-json-formatted-document-data/embed/#?secret=VD7ESsiJeP" data-secret="VD7ESsiJeP" width="600" height="338" title="&#8220;PostgreSQL: How to convert Table Data into JSON formatted Data?&#8221; &#8212; Database Research &amp; Development" frameborder="0" marginwidth="0" marginheight="0" scrolling="no"></iframe></p>
<p>In this post, I am going to share one more demonstration about PostgreSQL JSON. </p>
<blockquote><p>
In our system, I have stored communication message information in the form of JSON. This JSON column contains lots of different types of elements.<br />
Now one of module required to fetch this JSON array elements into a form of STRING Array only. (Something like comma separated).</p></blockquote>
<blockquote><p>We have different type of JSON functions and operator so I have achieved this solution using jsonb_array_elements.</p></blockquote>
<p><strong>Below is a full demonstration of this:</strong></p>
<p><strong>Create one table with sample data:</strong></p>
<pre class="crayon-plain-tag">CREATE TABLE tbl_TestJsonArray
(
	ID INT
	,JsonData JSONB
);

INSERT INTO tbl_TestJsonArray
VALUES (1,'{"Name": ["Anvesh","Roy","Jenny","Neevan"]}');</pre> </p>
<p><strong>SQL Query to convert JSON elements into String Array: </strong></p>
<pre class="crayon-plain-tag">SELECT 
	ID
	,(
		SELECT string_agg(trim(JsonString::text, '"'), ', ')
		FROM jsonb_array_elements(JsonData-&gt;'Name') JsonString
	) AS StringArray
FROM   tbl_TestJsonArray;</pre>
<strong>The Result:</strong></p>
<pre class="crayon-plain-tag">id  |       StringArray
----------------------------------
   1   | Anvesh, Roy, Jenny, Neevan</pre> </p>
]]></content:encoded>
					
		
		
			</item>
		<item>
		<title>PostgreSQL 9.5: How to Concatenate and Overwrite JSON Document</title>
		<link>https://www.dbrnd.com/2016/08/postgresql-9-5-how-to-concatenate-and-overwrite-json-document-json-jsonb-data-type-operator/</link>
		
		<dc:creator><![CDATA[Anvesh Patel]]></dc:creator>
		<pubDate>Sat, 13 Aug 2016 18:13:43 +0000</pubDate>
				<category><![CDATA[PostgreSQL]]></category>
		<category><![CDATA[Anvesh Patel]]></category>
		<category><![CDATA[CONCAT]]></category>
		<category><![CDATA[data type]]></category>
		<category><![CDATA[database]]></category>
		<category><![CDATA[database research and development]]></category>
		<category><![CDATA[dbrnd]]></category>
		<category><![CDATA[JSON]]></category>
		<category><![CDATA[jsonb]]></category>
		<category><![CDATA[overwrite]]></category>
		<category><![CDATA[plpgsql]]></category>
		<category><![CDATA[Postgres Query]]></category>
		<category><![CDATA[postgresql]]></category>
		<category><![CDATA[PostgreSQL Administrator]]></category>
		<category><![CDATA[PostgreSQL Error]]></category>
		<category><![CDATA[PostgreSQL Programming]]></category>
		<category><![CDATA[PostgreSQL Tips and Tricks]]></category>
		<guid isPermaLink="false">https://www.dbrnd.com/?p=3443</guid>

					<description><![CDATA[The PostgreSQL JSON data type is also one of the my favorite topic. I have written multiple article on PostgreSQL JSON data type. PostgreSQL 9.4: The JSON data type is Awesome (Part 1/3) PostgreSQL 9.5 introduced one new operator (&#124;&#124;) which used to perform Concatenate and Overwrite of JSON Document. The requirement is something like: [&#8230;]]]></description>
										<content:encoded><![CDATA[<p><a class="a2a_button_facebook" href="https://www.addtoany.com/add_to/facebook?linkurl=https%3A%2F%2Fwww.dbrnd.com%2F2016%2F08%2Fpostgresql-9-5-how-to-concatenate-and-overwrite-json-document-json-jsonb-data-type-operator%2F&amp;linkname=PostgreSQL%209.5%3A%20How%20to%20Concatenate%20and%20Overwrite%20JSON%20Document" title="Facebook" rel="nofollow noopener" target="_blank"></a><a class="a2a_button_twitter" href="https://www.addtoany.com/add_to/twitter?linkurl=https%3A%2F%2Fwww.dbrnd.com%2F2016%2F08%2Fpostgresql-9-5-how-to-concatenate-and-overwrite-json-document-json-jsonb-data-type-operator%2F&amp;linkname=PostgreSQL%209.5%3A%20How%20to%20Concatenate%20and%20Overwrite%20JSON%20Document" title="Twitter" rel="nofollow noopener" target="_blank"></a><a class="a2a_button_linkedin" href="https://www.addtoany.com/add_to/linkedin?linkurl=https%3A%2F%2Fwww.dbrnd.com%2F2016%2F08%2Fpostgresql-9-5-how-to-concatenate-and-overwrite-json-document-json-jsonb-data-type-operator%2F&amp;linkname=PostgreSQL%209.5%3A%20How%20to%20Concatenate%20and%20Overwrite%20JSON%20Document" title="LinkedIn" rel="nofollow noopener" target="_blank"></a><a class="a2a_button_pinterest" href="https://www.addtoany.com/add_to/pinterest?linkurl=https%3A%2F%2Fwww.dbrnd.com%2F2016%2F08%2Fpostgresql-9-5-how-to-concatenate-and-overwrite-json-document-json-jsonb-data-type-operator%2F&amp;linkname=PostgreSQL%209.5%3A%20How%20to%20Concatenate%20and%20Overwrite%20JSON%20Document" title="Pinterest" rel="nofollow noopener" target="_blank"></a><a class="a2a_button_reddit" href="https://www.addtoany.com/add_to/reddit?linkurl=https%3A%2F%2Fwww.dbrnd.com%2F2016%2F08%2Fpostgresql-9-5-how-to-concatenate-and-overwrite-json-document-json-jsonb-data-type-operator%2F&amp;linkname=PostgreSQL%209.5%3A%20How%20to%20Concatenate%20and%20Overwrite%20JSON%20Document" title="Reddit" rel="nofollow noopener" target="_blank"></a><a class="a2a_button_pocket" href="https://www.addtoany.com/add_to/pocket?linkurl=https%3A%2F%2Fwww.dbrnd.com%2F2016%2F08%2Fpostgresql-9-5-how-to-concatenate-and-overwrite-json-document-json-jsonb-data-type-operator%2F&amp;linkname=PostgreSQL%209.5%3A%20How%20to%20Concatenate%20and%20Overwrite%20JSON%20Document" title="Pocket" rel="nofollow noopener" target="_blank"></a><a class="a2a_dd addtoany_share_save addtoany_share" href="https://www.addtoany.com/share#url=https%3A%2F%2Fwww.dbrnd.com%2F2016%2F08%2Fpostgresql-9-5-how-to-concatenate-and-overwrite-json-document-json-jsonb-data-type-operator%2F&#038;title=PostgreSQL%209.5%3A%20How%20to%20Concatenate%20and%20Overwrite%20JSON%20Document" data-a2a-url="https://www.dbrnd.com/2016/08/postgresql-9-5-how-to-concatenate-and-overwrite-json-document-json-jsonb-data-type-operator/" data-a2a-title="PostgreSQL 9.5: How to Concatenate and Overwrite JSON Document"></a></p><p>The PostgreSQL JSON data type is also one of the my favorite topic.<br />
I have written multiple article on PostgreSQL JSON data type. </p>
<blockquote class="wp-embedded-content" data-secret="VwMBqIgKFg"><p><a href="https://www.dbrnd.com/2016/02/postgresql-9-4-the-json-data-type-is-awesome-part-1/">PostgreSQL 9.4: The JSON data type is Awesome (Part 1/3)</a></p></blockquote>
<p><iframe loading="lazy" class="wp-embedded-content" sandbox="allow-scripts" security="restricted"  src="https://www.dbrnd.com/2016/02/postgresql-9-4-the-json-data-type-is-awesome-part-1/embed/#?secret=VwMBqIgKFg" data-secret="VwMBqIgKFg" width="600" height="338" title="&#8220;PostgreSQL 9.4: The JSON data type is Awesome (Part 1/3)&#8221; &#8212; Database Research &amp; Development" frameborder="0" marginwidth="0" marginheight="0" scrolling="no"></iframe></p>
<p><strong>PostgreSQL 9.5 introduced one new operator (||) which used to perform Concatenate and Overwrite of JSON Document.</strong></p>
<blockquote><p>The requirement is something like: we have stored one JSON string or document into PostgreSQL. Now we require to add any new key or elements into that document. </p></blockquote>
<blockquote><p>It was not possible in the previous version of PostgreSQL, but now we can use (||) this operator to add or overwrite particular key into the JSON document. </p></blockquote>
<p><strong>Please go through this full practical demonstration:</strong></p>
<p><strong>Create a table with Sample data:</strong></p>
<pre class="crayon-plain-tag">CREATE TABLE tbl_TestJSON
(
	ID INTEGER PRIMARY KEY
	,DepartName VARCHAR(250)
	,EmployeeDetails JSONB
	,Address JSONB
);

INSERT INTO tbl_TestJSON
VALUES 
(
	1
	,'Sales'
	,'
	{"employees":[
	    {"firstName":"Anvesh", "lastName":"Patel"},
	    {"firstName":"Eric", "lastName":"Marin"},
	    {"firstName":"Martin", "lastName":"Loother"}
	]}'
	,'{"address" : "Hyderabad"}'
)
,(
	2
	,'Production'
	,'
	{"employees":[
	    {"firstName":"Neevan", "lastName":"Patel"},
	    {"firstName":"Roy", "lastName":"Boon"},
	    {"firstName":"Nancy", "lastName":"Shah"}
	]}'
	,'{"address" : "Ahmedabad"}'
);</pre> </p>
<p><strong>Using (||) operator can concat two JSON String:</strong><br />
In the below example, you can see &#8220;address&#8221; key is merged with &#8220;employees&#8221; key.</p>
<pre class="crayon-plain-tag">SELECT EmployeeDetails || Address AS JsonData FROM tbl_TestJSON;
/*
		   JsonData
------------------------------------------------
{"address": "Hyderabad"
 ,"employees": 
	[{"lastName": "Patel", "firstName": "Anvesh"}
	,{"lastName": "Marin", "firstName": "Eric"}
	,{"lastName": "Loother", "firstName": "Martin"}
	]
}
{"address": "Ahmedabad"
 ,"employees": 
	[{"lastName": "Patel", "firstName": "Neevan"}
	,{"lastName": "Boon", "firstName": "Roy"}
	,{"lastName": "Shah", "firstName": "Nancy"}
	]
}*/</pre> </p>
<p><strong>Using (||) operator can overwrite the JSON string:</strong><br />
In the below example, you can see the replacement of &#8220;address&#8221; value. </p>
<pre class="crayon-plain-tag">SELECT EmployeeDetails || Address || '{"address": "Pune"}'FROM tbl_TestJSON;
/*
		  JsonData
-------------------------------------------------
{"address": "Pune"
 ,"employees": 
	    [{"lastName": "Patel", "firstName": "Anvesh"}
	    ,{"lastName": "Marin", "firstName": "Eric"}
	    ,{"lastName": "Loother", "firstName": "Martin"}
	    ]
}
{"address": "Pune"
 ,"employees": 
	   [{"lastName": "Patel", "firstName": "Neevan"}
	   ,{"lastName": "Boon", "firstName": "Roy"}
	   ,{"lastName": "Shah", "firstName": "Nancy"}
	   ]
}*/</pre> </p>
]]></content:encoded>
					
		
		
			</item>
		<item>
		<title>PostgreSQL: How to convert Table Data into JSON formatted Data?</title>
		<link>https://www.dbrnd.com/2016/08/postgresql-how-to-convert-table-data-record-into-json-formatted-document-data/</link>
		
		<dc:creator><![CDATA[Anvesh Patel]]></dc:creator>
		<pubDate>Fri, 05 Aug 2016 05:38:22 +0000</pubDate>
				<category><![CDATA[PostgreSQL]]></category>
		<category><![CDATA[Anvesh Patel]]></category>
		<category><![CDATA[database]]></category>
		<category><![CDATA[database research and development]]></category>
		<category><![CDATA[dbrnd]]></category>
		<category><![CDATA[JSON]]></category>
		<category><![CDATA[json_agg]]></category>
		<category><![CDATA[plpgsql]]></category>
		<category><![CDATA[Postgres Query]]></category>
		<category><![CDATA[postgresql]]></category>
		<category><![CDATA[PostgreSQL Administrator]]></category>
		<category><![CDATA[PostgreSQL Error]]></category>
		<category><![CDATA[PostgreSQL Programming]]></category>
		<category><![CDATA[PostgreSQL Tips and Tricks]]></category>
		<category><![CDATA[row_to_json]]></category>
		<guid isPermaLink="false">https://www.dbrnd.com/?p=1809</guid>

					<description><![CDATA[PostgreSQL 9.4 introduced very powerful data type called JSON data type. It also introduced a variety of new operators and functions related to JSON data type. This is one of the interesting topics for us and I have recently published a series of articles on PostgreSQL JSON Data type. You can visit related articles here: [&#8230;]]]></description>
										<content:encoded><![CDATA[<p><a class="a2a_button_facebook" href="https://www.addtoany.com/add_to/facebook?linkurl=https%3A%2F%2Fwww.dbrnd.com%2F2016%2F08%2Fpostgresql-how-to-convert-table-data-record-into-json-formatted-document-data%2F&amp;linkname=PostgreSQL%3A%20How%20to%20convert%20Table%20Data%20into%20JSON%20formatted%20Data%3F" title="Facebook" rel="nofollow noopener" target="_blank"></a><a class="a2a_button_twitter" href="https://www.addtoany.com/add_to/twitter?linkurl=https%3A%2F%2Fwww.dbrnd.com%2F2016%2F08%2Fpostgresql-how-to-convert-table-data-record-into-json-formatted-document-data%2F&amp;linkname=PostgreSQL%3A%20How%20to%20convert%20Table%20Data%20into%20JSON%20formatted%20Data%3F" title="Twitter" rel="nofollow noopener" target="_blank"></a><a class="a2a_button_linkedin" href="https://www.addtoany.com/add_to/linkedin?linkurl=https%3A%2F%2Fwww.dbrnd.com%2F2016%2F08%2Fpostgresql-how-to-convert-table-data-record-into-json-formatted-document-data%2F&amp;linkname=PostgreSQL%3A%20How%20to%20convert%20Table%20Data%20into%20JSON%20formatted%20Data%3F" title="LinkedIn" rel="nofollow noopener" target="_blank"></a><a class="a2a_button_pinterest" href="https://www.addtoany.com/add_to/pinterest?linkurl=https%3A%2F%2Fwww.dbrnd.com%2F2016%2F08%2Fpostgresql-how-to-convert-table-data-record-into-json-formatted-document-data%2F&amp;linkname=PostgreSQL%3A%20How%20to%20convert%20Table%20Data%20into%20JSON%20formatted%20Data%3F" title="Pinterest" rel="nofollow noopener" target="_blank"></a><a class="a2a_button_reddit" href="https://www.addtoany.com/add_to/reddit?linkurl=https%3A%2F%2Fwww.dbrnd.com%2F2016%2F08%2Fpostgresql-how-to-convert-table-data-record-into-json-formatted-document-data%2F&amp;linkname=PostgreSQL%3A%20How%20to%20convert%20Table%20Data%20into%20JSON%20formatted%20Data%3F" title="Reddit" rel="nofollow noopener" target="_blank"></a><a class="a2a_button_pocket" href="https://www.addtoany.com/add_to/pocket?linkurl=https%3A%2F%2Fwww.dbrnd.com%2F2016%2F08%2Fpostgresql-how-to-convert-table-data-record-into-json-formatted-document-data%2F&amp;linkname=PostgreSQL%3A%20How%20to%20convert%20Table%20Data%20into%20JSON%20formatted%20Data%3F" title="Pocket" rel="nofollow noopener" target="_blank"></a><a class="a2a_dd addtoany_share_save addtoany_share" href="https://www.addtoany.com/share#url=https%3A%2F%2Fwww.dbrnd.com%2F2016%2F08%2Fpostgresql-how-to-convert-table-data-record-into-json-formatted-document-data%2F&#038;title=PostgreSQL%3A%20How%20to%20convert%20Table%20Data%20into%20JSON%20formatted%20Data%3F" data-a2a-url="https://www.dbrnd.com/2016/08/postgresql-how-to-convert-table-data-record-into-json-formatted-document-data/" data-a2a-title="PostgreSQL: How to convert Table Data into JSON formatted Data?"></a></p><p>PostgreSQL 9.4 introduced very powerful data type called JSON data type. It also introduced a variety of new operators and functions related to JSON data type.</p>
<blockquote><p>This is one of the interesting topics for us and I have recently published a series of articles on PostgreSQL JSON Data type.</p></blockquote>
<p><strong>You can visit related articles here:</strong></p>
<p><strong><a href="https://www.dbrnd.com/2016/02/postgresql-9-4-the-json-data-type-is-awesome-part-1/" target="_blank">PostgreSQL 9.4: The JSON data type is Awesome (Part 1/3).</a><br />
<a href="https://www.dbrnd.com/2016/02/postgresql-9-4-introduced-json-functions-and-operators-part-2/" target="_blank">PostgreSQL 9.4: Introduced JSON Functions and Operators (Part 2/3).</a><br />
<a href="https://www.dbrnd.com/2016/02/postgresql-9-4-indexing-on-jsonb-data-type-part-3/" target="_blank">PostgreSQL 9.4: Indexing on jsonb Data Type (Part 3/3).</a></strong></p>
<p>In this post, I am also going share one of the important query to convert PostgreSQL tabular data into JSON formatted data.</p>
<p>Generally, We are storing JSON formatted data into PostgreSQL and access base on the different filters.</p>
<blockquote><p>Here, I am sharing one type of utility script to convert PostgreSQL table data into JSON formatted data. Sometimes it requires to populate JSON formatted data for a web service purpose.</p></blockquote>
<p>I am doing this using, json_agg and row_to_json function.<br />
<strong>json_agg(expression) :</strong> aggregates values as a JSON array.<br />
<strong>row_to_json(record [, pretty_bool]) :</strong> Returns the row as JSON.</p>
<p><strong>Below is a full demonstration of this:</strong></p>
<p><strong>First, create table with sample data:</strong></p><pre class="crayon-plain-tag">CREATE TABLE tbl_EmployeeDetails
(
	EmpID INTEGER
	,DepartmenetName VARCHAR(50)
	,EmpFirstName VARCHAR(50)
	,EmpLastName VARCHAR(50)
);

INSERT INTO tbl_EmployeeDetails VALUES
(1,'Sales','Anvesh','Patel')
,(2,'Sales','Neevan','Patel')
,(3,'Order','Roy','Loother')
,(4,'Marketing','Martin','Farook')
,(5,'Marketing','Jenny','Pandya')
,(6,'Marketing','Mahi','Patel');</pre><p>
<strong>Script to convert data into JSON format without column name for key:</strong></p><pre class="crayon-plain-tag">SELECT 
	DepartmenetName
	,json_agg(row_to_json((EmpFirstName, EmpLastName))) AS JsonData
FROM tbl_EmployeeDetails 
GROUP BY DepartmenetName;</pre><p>
<strong>The Result:</strong></p>
<p><a href="https://www.dbrnd.com/wp-content/uploads/2016/02/PostgreSQLJsonData1.png" rel="attachment wp-att-1815"><img loading="lazy" decoding="async" class="alignnone wp-image-1815 size-full" title="PostgreSQL Json Data" src="https://www.dbrnd.com/wp-content/uploads/2016/02/PostgreSQLJsonData1.png" alt="PostgreSQL Json Data" width="773" height="100" srcset="https://www.dbrnd.com/wp-content/uploads/2016/02/PostgreSQLJsonData1.png 773w, https://www.dbrnd.com/wp-content/uploads/2016/02/PostgreSQLJsonData1-300x39.png 300w, https://www.dbrnd.com/wp-content/uploads/2016/02/PostgreSQLJsonData1-750x97.png 750w, https://www.dbrnd.com/wp-content/uploads/2016/02/PostgreSQLJsonData1-150x19.png 150w" sizes="auto, (max-width: 773px) 100vw, 773px" /></a></p>
<p><strong>Script to convert data into JSON format with column name for key:</strong></p><pre class="crayon-plain-tag">SELECT 
	DepartmenetName
	,json_agg(row_to_json
	(
	  (SELECT ColumnName FROM (SELECT EmpFirstName, EmpLastName) AS ColumnName (EmpFirstName, EmpLastName))
	)) AS JsonData
FROM tbl_EmployeeDetails
GROUP BY DepartmenetName;</pre><p>
<strong>The Result:</strong></p>
<p><a href="https://www.dbrnd.com/wp-content/uploads/2016/02/PostgreSQLJsonData2.png" rel="attachment wp-att-1816"><img loading="lazy" decoding="async" class="alignnone wp-image-1816 size-full" title="PostgreSQL Json Data" src="https://www.dbrnd.com/wp-content/uploads/2016/02/PostgreSQLJsonData2.png" alt="PostgreSQL Json Data" width="1170" height="98" srcset="https://www.dbrnd.com/wp-content/uploads/2016/02/PostgreSQLJsonData2.png 1170w, https://www.dbrnd.com/wp-content/uploads/2016/02/PostgreSQLJsonData2-300x25.png 300w, https://www.dbrnd.com/wp-content/uploads/2016/02/PostgreSQLJsonData2-768x64.png 768w, https://www.dbrnd.com/wp-content/uploads/2016/02/PostgreSQLJsonData2-1024x86.png 1024w, https://www.dbrnd.com/wp-content/uploads/2016/02/PostgreSQLJsonData2-750x63.png 750w, https://www.dbrnd.com/wp-content/uploads/2016/02/PostgreSQLJsonData2-150x13.png 150w" sizes="auto, (max-width: 1170px) 100vw, 1170px" /></a></p>
]]></content:encoded>
					
		
		
			</item>
		<item>
		<title>PostgreSQL: How to create an index on JSON Property?</title>
		<link>https://www.dbrnd.com/2016/07/postgresql-how-to-create-an-index-on-json-property/</link>
		
		<dc:creator><![CDATA[Anvesh Patel]]></dc:creator>
		<pubDate>Thu, 28 Jul 2016 18:23:13 +0000</pubDate>
				<category><![CDATA[PostgreSQL]]></category>
		<category><![CDATA[Anvesh Patel]]></category>
		<category><![CDATA[database]]></category>
		<category><![CDATA[database research and development]]></category>
		<category><![CDATA[dbrnd]]></category>
		<category><![CDATA[index]]></category>
		<category><![CDATA[JSON]]></category>
		<category><![CDATA[plpgsql]]></category>
		<category><![CDATA[Postgres Query]]></category>
		<category><![CDATA[postgresql]]></category>
		<category><![CDATA[PostgreSQL Administrator]]></category>
		<category><![CDATA[PostgreSQL Error]]></category>
		<category><![CDATA[PostgreSQL Programming]]></category>
		<category><![CDATA[PostgreSQL Tips and Tricks]]></category>
		<guid isPermaLink="false">https://www.dbrnd.com/?p=2177</guid>

					<description><![CDATA[I have written a couple of articles about the awesome JSON data type of the PostgreSQL. I am really very impressed with RDBMS + NoSQL (JSON) implementation at one place. Recently, I have published one article about to create GIN index on JSON data of PostgreSQL. In this post, I am sharing one demonstration to [&#8230;]]]></description>
										<content:encoded><![CDATA[<p><a class="a2a_button_facebook" href="https://www.addtoany.com/add_to/facebook?linkurl=https%3A%2F%2Fwww.dbrnd.com%2F2016%2F07%2Fpostgresql-how-to-create-an-index-on-json-property%2F&amp;linkname=PostgreSQL%3A%20How%20to%20create%20an%20index%20on%20JSON%20Property%3F" title="Facebook" rel="nofollow noopener" target="_blank"></a><a class="a2a_button_twitter" href="https://www.addtoany.com/add_to/twitter?linkurl=https%3A%2F%2Fwww.dbrnd.com%2F2016%2F07%2Fpostgresql-how-to-create-an-index-on-json-property%2F&amp;linkname=PostgreSQL%3A%20How%20to%20create%20an%20index%20on%20JSON%20Property%3F" title="Twitter" rel="nofollow noopener" target="_blank"></a><a class="a2a_button_linkedin" href="https://www.addtoany.com/add_to/linkedin?linkurl=https%3A%2F%2Fwww.dbrnd.com%2F2016%2F07%2Fpostgresql-how-to-create-an-index-on-json-property%2F&amp;linkname=PostgreSQL%3A%20How%20to%20create%20an%20index%20on%20JSON%20Property%3F" title="LinkedIn" rel="nofollow noopener" target="_blank"></a><a class="a2a_button_pinterest" href="https://www.addtoany.com/add_to/pinterest?linkurl=https%3A%2F%2Fwww.dbrnd.com%2F2016%2F07%2Fpostgresql-how-to-create-an-index-on-json-property%2F&amp;linkname=PostgreSQL%3A%20How%20to%20create%20an%20index%20on%20JSON%20Property%3F" title="Pinterest" rel="nofollow noopener" target="_blank"></a><a class="a2a_button_reddit" href="https://www.addtoany.com/add_to/reddit?linkurl=https%3A%2F%2Fwww.dbrnd.com%2F2016%2F07%2Fpostgresql-how-to-create-an-index-on-json-property%2F&amp;linkname=PostgreSQL%3A%20How%20to%20create%20an%20index%20on%20JSON%20Property%3F" title="Reddit" rel="nofollow noopener" target="_blank"></a><a class="a2a_button_pocket" href="https://www.addtoany.com/add_to/pocket?linkurl=https%3A%2F%2Fwww.dbrnd.com%2F2016%2F07%2Fpostgresql-how-to-create-an-index-on-json-property%2F&amp;linkname=PostgreSQL%3A%20How%20to%20create%20an%20index%20on%20JSON%20Property%3F" title="Pocket" rel="nofollow noopener" target="_blank"></a><a class="a2a_dd addtoany_share_save addtoany_share" href="https://www.addtoany.com/share#url=https%3A%2F%2Fwww.dbrnd.com%2F2016%2F07%2Fpostgresql-how-to-create-an-index-on-json-property%2F&#038;title=PostgreSQL%3A%20How%20to%20create%20an%20index%20on%20JSON%20Property%3F" data-a2a-url="https://www.dbrnd.com/2016/07/postgresql-how-to-create-an-index-on-json-property/" data-a2a-title="PostgreSQL: How to create an index on JSON Property?"></a></p><p>I have written a couple of articles about the awesome JSON data type of the PostgreSQL.<br />
I am really very impressed with RDBMS + NoSQL (JSON) implementation at one place. </p>
<p><a href="https://www.dbrnd.com/2016/02/postgresql-9-4-indexing-on-jsonb-data-type-part-3/" target="_blank"><strong>Recently, I have published one article about to create GIN index on JSON data of PostgreSQL. </strong></a></p>
<p>In this post, I am sharing one demonstration to create an index on a particular element or property of JSON data.</p>
<p>We can also create GIN index on whole JSON column, but whenever we require an index on particular JSON property, we should create it.</p>
<p><strong>First, create a sample table:</strong></p>
<pre class="crayon-plain-tag">CREATE TABLE tbl_JSONDataIndex
(
	ID INTEGER PRIMARY KEY
	,DepartName VARCHAR(250)
	,EmployeeDetails JSONB
);</pre> </p>
<p><strong>Create an index on JSON property:</strong><br />
I have created one integer index on Employee&#8217;s Age property. </p>
<pre class="crayon-plain-tag">CREATE INDEX idx_JSON_EmpAge ON 
tbl_JSONDataIndex(cast(EmployeeDetails-&gt;&gt;'age' AS INT));</pre> </p>
<p><strong>Insert few sample records:</strong></p>
<pre class="crayon-plain-tag">INSERT INTO tbl_JSONDataIndex
VALUES 
(
	1
	,'Sales'
	,'	
	{
		"firstName":"Anvesh"
		,"lastName":"Patel"
		,"gender":"Male"
		,"address":"Hyederabad"
		,"age":28
		,"role":
		[
			"admin"
			,"vendor"
		]
	}	    
	'
)
,(
	2
	,'Production'
	,'	
	{
		"firstName":"Neevan"
		,"lastName":"Patel"
		,"gender":"Male"
		,"address":"Hyederabad"
		,"age":20
		,"role":
		[
			"user"
			,"production"
		]
	}	    
	'
);</pre> </p>
]]></content:encoded>
					
		
		
			</item>
	</channel>
</rss>
