SQL Server Data Types To JSON Data Types

Facebooktwittergoogle_plusredditpinterestlinkedinmail

In SQL Server 2016 they are added support for outputting your query results in JSON. When you serialize your data to JSON using the FOR JSON clause, a data type conversion happens. The data types are converted from SQL Server data types to JSON supported data types.

For more information on how to convert your result set to JSON: www.sqlserver.info/syntax/json-in-sql-server/

Here is a quick reference table showing the data type conversions that are happening:

SQL Data Type JSON Data Type
VARCHAR/NVARCHAR String
CHAR/NCHAR String
INT Number
BIGINT Number
FLOAT Number
DECIMAL Number
NUMERIC Number
BIT Boolean
DATETIME String
DATETIME2 String
DATE String
TIME String
DATETIMEOFFSET String
VARBINARY Base64-encoded string
BINARY Base64-encoded string
IMAGE Base64-encoded string
TIMESTAMP Base64-encoded string
ROWVERSION Base64-encoded string
UNIQUEIIDENTIFIER String
MONEY String