Alternative to "FOR JSON" in SQL Server 2012?

No. JSON support was new in SQL Server 2016.

If you want to convert data to JSON, you have a few options:

  • Fetch the rows as you would any other query result, and convert it in the application tier (like C#, Java, etc)
  • Build T-SQL logic in a stored procedure or function to convert it to JSON yourself (but keep in mind that you won't be able to use "FOR JSON PATH" the exact same way 2016 does)
  • Build CLR logic to do it (again, won't be compatible with "FOR JSON PATH")

In SQL Server 2012, you can use FOR XML. For my case, this was a viable alternative to JSON, since I was just passing the string to a browser.