I am using SQL Server 2008 and want to convert table data into json format. Can I convert it directly through firing query?
Simple answer is: no.
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.
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.
I have created a stored procedure that can take your table and output JSON. You can find it at
Once you run the stored procedure, you can output your table by making a call like the following:
EXEC SQLTableOrViewToJSON 'MyTable', 'C:\WhereIStowMyJSON\'
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:
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With