| title | JSON data type (preview) | ||
|---|---|---|---|
| description | The native JSON data type provides advantages for storing JSON data over varchar or nvarchar. Learn more about the JSON data type. | ||
| author | WilliamDAssafMSFT | ||
| ms.author | wiassaf | ||
| ms.reviewer | randolphwest, jovanpop, umajay | ||
| ms.date | 05/21/2025 | ||
| ms.service | sql | ||
| ms.subservice | t-sql | ||
| ms.topic | reference | ||
| ms.custom |
|
||
| helpviewer_keywords |
|
||
| monikerRange | =azuresqldb-current||=azuresqldb-mi-current |
[!INCLUDE sqlserver2025-asdb-asmi-fabricsqldb]
The native json data type that stores JSON documents in a native binary format.
The json type provides a high-fidelity storage of JSON documents optimized for easy querying and manipulation, and provides the following benefits over storing JSON data in varchar or nvarchar:
- More efficient reads, as the document is already parsed
- More efficient writes, as the query can update individual values without accessing the entire document
- More efficient storage, optimized for compression
- No change in compatibility with existing code
The json type internally stores data using UTF-8 encoding, Latin1_General_100_BIN2_UTF8. This behavior matches the JSON specification.
For more information on querying JSON data, see JSON data in SQL Server.
The usage syntax for the json type is similar to all other SQL Server data types in a table.
column_name JSON [NOT NULL | NULL] [CHECK(constraint_expression)] [DEFAULT(default_expression)]
The json type can be used in column definition contained in a CREATE TABLE statement, for example:
CREATE TABLE Orders (order_id int, order_details JSON NOT NULL);Constraints can be specified as part of the column definition, for example:
CREATE TABLE Orders (order_id int, order_details JSON NOT NULL
CHECK (JSON_PATH_EXISTS(order_details, '$.basket') = 1)
);JSON function support was first introduced in [!INCLUDE sssql16-md]. The native json type was introduced in 2024 in Azure SQL Database and Azure SQL Managed Instance.
json is available under all database compatibility levels.
Note
The JSON data type:
- is generally available for Azure SQL Database and Azure SQL Managed Instance configured with the Always-up-to-date update policy.
- is in preview for [!INCLUDE sssql25-md].
Note
modify method is currently in preview and only available in [!INCLUDE sssql25-md].
The native json type supports the modify method. Use modify to modify JSON documents stored in a column. The modify method has optimizations to perform in-place modifications to the data where possible, and is the preferred way to modify a JSON document in a json type column.
For JSON strings, if the new value is less than or equal to the existing value, then in-place modification is possible.
For JSON numbers, if the new value is of the same type, or within the range of the existing value, then in-place modification is possible.
DROP TABLE IF EXISTS JsonTable;
CREATE TABLE JsonTable ( id int PRIMARY KEY, d JSON );
INSERT INTO JsonTable (id, d) VALUES(1, '{"a":1, "b":"abc", "c":true}');
UPDATE JsonTable
SET d.modify('$.a', 14859)
WHERE id = 1;
UPDATE JsonTable
SET d.modify('$.b', 'def')
WHERE id = 1;All JSON functions support the json type with no code changes or usage difference necessary.
OPENJSONcurrently does not support the json data type on some platforms. For more information, see Limitations.
For a complete list of JSON functions, see JSON functions.
There are no special index types for JSON data.
The json type can't be used as key column in a CREATE INDEX statement. However, a json column can be specified as an included column in an index definition. Additionally, a json column can appear in the WHERE clause of a filtered index.
Explicit conversion using CAST or CONVERT from the json type can be done to char, nchar, varchar, and nvarchar types. All implicit conversions aren't allowed, similar to the behavior of xml. Similarly, only char, nchar, varchar, and nvarchar can be explicitly converted to the json type.
The json type can't be used with the sql_variant type or assigned to a sql_variant variable or column. This restriction similar to varchar(max), varbinary(max), nvarchar(max), xml, and CLR-based data types.
You can convert existing columns, like a varchar(max) column to json using ALTER TABLE. Similar to the xml data type, you cannot convert a json column to any of the string or binary types using ALTER TABLE.
For more information, see Data type conversion.
The json type can be used as a parameter or return type in a user-defined function, or the parameter of a stored procedure. The json type is compatible with triggers and views.
Currently, the bcp tool's native format contains the json document as varchar or nvarchar. You must specify a format file to designate a json data type column.
Creation of alias type using CREATE TYPE for the json type isn't allowed. This is same behavior as xml type.
Using SELECT ... INTO with the JSON type creates a table with the JSON type.
- The behavior of
CAST ( ... AS JSON)returns a json type, but the sp_describe_first_result_set system stored procedure doesn't correctly return the json data type. Therefore, many data access clients and driver will see a varchar or nvarchar data type.- Currently, TDS >= 7.4 (with UTF-8) sees varchar(max) with
Latin_General_100_bin2_utf8. - Currently, TDS < 7.4 sees nvarchar(max) with database collation.
- Currently, TDS >= 7.4 (with UTF-8) sees varchar(max) with
- Currently, the
OPENJSON()function doesn't accept the json type in some platforms. Currently, it is an implicit conversion. Explicitly convert to nvarchar(max) first.- In SQL Server 2025 (Preview), the
OPENJSON()function does supports the json type. For more information, see Key JSON capabilities in SQL Server 2025.
- In SQL Server 2025 (Preview), the