I am working with JSON in SSMS in SQL Server 2016. Is there any way to get around that the results of a FOR JSON statement are presented as an XML column?
Are there any settings changes, additional components, external tools, etc. or even hacks to make this less painful?
In my ideal world, clicking on a JSON column (or an XML column for that matter) would open in my text editor of choice, such as Visual Studio Code, with SSMS knowing that the string in the column is JSON and saving it to file with a .json extension.
JSON functions, first introduced in SQL Server 2016, enable you to combine NoSQL and relational concepts in the same database.
Use the FOR JSON clause to simplify client applications by delegating the formatting of JSON output from the app to SQL Server. Azure Data Studio is the recommended query editor for JSON queries because it auto-formats the JSON results (as seen in this article) instead of displaying a flat string.
All modern web applications support JSON and it is one of the well-known data interchange formats. Now, SQL Server also supports the JSON format. There is no specific data type for JSON SQL Server like XML.
When a query references only one table, the results of the FOR JSON AUTO clause are similar to the results of FOR JSON PATH . In this case, FOR JSON AUTO doesn't create nested objects. The only difference is that FOR JSON AUTO outputs dot-separated aliases (for example, Info.
Azure Data Studio will do most of what you want.
Run your query:
Clicking on the RESULTS will open a new tab with formatted JSON:
I just want to add that the "MsSql Extension" for VS Code is really starting to be very useful with the kind of JSON support that you would expect.
It doesn't replace SSMS but works for basic SQL work and when you click on a JSON column it actually opens in formatted JSON! The added bonus is that I usually have VS Code open for other things anyway these days.
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