Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to convert data to json format in SQL Server 2008?

I am using SQL Server 2008 and want to convert table data into json format. Can I convert it directly through firing query?

like image 902
alax Avatar asked Dec 19 '15 17:12

alax


People also ask

Is JSON compatible with SQL Server 2008?

Simple answer is: no.

Is there a JSON data type in SQL Server?

SQL Server and Azure SQL Database have native JSON functions that enable you to parse JSON documents using standard SQL language. You can store JSON documents in SQL Server or SQL Database and query JSON data as in a NoSQL database.

How can I get SQL data from JSON format?

Format query results as JSON, or export data from SQL Server as JSON, by adding the FOR JSON clause to a SELECT statement. Use the FOR JSON clause to simplify client applications by delegating the formatting of JSON output from the app to SQL Server.


2 Answers

I have created a stored procedure that can take your table and output JSON. You can find it at

  • GitHub - SQLTableOrViewToJSON

Once you run the stored procedure, you can output your table by making a call like the following:

EXEC SQLTableOrViewToJSON 'MyTable', 'C:\WhereIStowMyJSON\'
like image 99
Ahliana Avatar answered Sep 30 '22 16:09

Ahliana


Built in support for formatting query results is added in SQL Server 2016 and it will be available in Azure Database. In older versions you would need to use CLR or some heavy TSQL like:

  • Producing JSON Documents from SQL Server queries via TSQL
like image 21
Jovan MSFT Avatar answered Sep 30 '22 15:09

Jovan MSFT