Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

SQL Server 2016 SSMS Json Formatting

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.

like image 862
WillC Avatar asked Oct 19 '18 19:10

WillC


People also ask

Does SQL 2016 support JSON?

JSON functions, first introduced in SQL Server 2016, enable you to combine NoSQL and relational concepts in the same database.

Does SQL use JSON formatting?

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.

Does SQL Server support JSON datatype?

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.

What is the difference between JSON Auto and JSON path?

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.


2 Answers

Azure Data Studio will do most of what you want.

Run your query:

enter image description here

Clicking on the RESULTS will open a new tab with formatted JSON:

enter image description here

like image 166
Jon Crowell Avatar answered Nov 15 '22 05:11

Jon Crowell


enter image description here

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.

like image 25
WillC Avatar answered Nov 15 '22 05:11

WillC