Skip to content

Support new native JSON data type #1778

@BramMeerten

Description

@BramMeerten

I'm using the following database: Microsoft SQL Azure (RTM) - 12.0.2000.8. It supports the native JSON type:

CREATE TABLE [my_table]
(
    attributes       JSON                 NOT NULL,
    -- ...
)
GO

More info here:

JSON function support was first introduced in SQL Server 2016 (13.x). The native json type was introduced in Azure SQL Database and Azure SQL Managed Instance, and is also available in SQL Server 2025 (17.x) Preview.

But this type is not available in node-mssql, which causes some problems for me. Could this be added?


Below my use case (although I don't think it's relevant for this feature request):
I programmatically create a temp table:

  const table = new sql.Table('#TMPmytable');
  table.create = true;
  // ...
  table.columns.add('attributes', sql.NVarChar(sql.MAX), { nullable: true });

As you can see I'm forced to use NVARCHAR(MAX) which some articles suggest, because before JSON was a native type, this was the underlying type.

When I'm trying to copy data from the temp table to my actual table (which does has a column with JSON type), I get errors when comparing columns from source (temp) and target table:

  UPDATE target
    SET
      -- ...
  FROM my_table AS target
    JOIN #TMPmytable AS source
        ON -- ...
  WHERE
     -- ...
    OR ISNULL(target.attributes,'') <> ISNULL(source.attributes,'')
The data types json and nvarchar(max) are incompatible in the not equal to operator.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions