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

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\'

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