Format Query as JSON
JSON (JavaScript Object Notation) is a file format used to transmit data from various applications, very similar to XML, it also used to stored NoSQL unstructured data, and because of this versatility, Many REST applications and web services use it. Since this is a standard file format, you should be able to generate data in JSON format from SQL Server. Fortunately, since SQL Server 2016, there is a native way to do it, in this post I will show you how to do it. Generate a simple JSON file The most basic syntax to generate a JSON file is this: SELECT <field list> FROM <YourObject> FOR JSON AUTO Using this simple test table with 10 records as an example: SELECT TOP 10 * FROM [dbo].[MyTestTable] If we use JSON AUTO on this sample data we will have the following output: SELECT TOP 10 * FROM [dbo].[MyTestTable] FOR JSON AUTO Query executed Part of the JSON AUTO output Using dot syntax For most of real-world application