JSON_OBJECT()

JSON_OBJECT constructs JSON object text from zero or more expressions.

Signature

JSON_OBJECT ( [ <json_key_value> [ , ...n ] ] [ json_null_clause ] [ RETURNING json ] )

<json_key_value> ::= json_key_name : value_expression

<json_null_clause> ::=
      NULL ON NULL
    | ABSENT ON NULL

Parameters

  • json_key_name — A character expression that defines the value of the JSON key name.
  • value_expression — An expression that defines the value of the JSON key.
  • json_null_clause — Can be used to control the behavior of `JSON_OBJECT` function when value_expression is `NULL`. The option `NULL ON NULL` converts the SQL `NULL` value into a JSON null value when generating the JSON key value. The option `ABSENT ON NULL` will omit the entire key if the value is `NULL`. The default setting for this option is `NULL ON NULL`.

Examples

SELECT JSON_OBJECT();
{}
SELECT JSON_OBJECT('name':'value', 'type':1);
{"name":"value","type":1}
SELECT JSON_OBJECT('name':'value', 'type':NULL ABSENT ON NULL);
{"name":"value"}

Run against SQL Server 16.0.4265.3 on 2026-09-13. This is the output we got, not the documentation’s.

Available on

  • SQL Server 2022 and later
  • Azure SQL Database
  • Azure SQL Managed Instance
  • Microsoft Fabric warehouse
  • Fabric SQL database

Signature and description adapted from the Microsoft SQL documentation, used under the CC BY 4.0. SQL Server and Azure are trademarks of the Microsoft group of companies. This page is not affiliated with Microsoft.