包含空值

FOR JSON 子句忽略单元格中的 NULL 值。如果要为包含 NULL 值的单元格生成 key:null 对,请在查询中添加 INCLUDE_NULL_VALUES 选项:

SELECT top 3 object_id, name, type, principal_id
FROM sys.objects
FOR JSON PATH, INCLUDE_NULL_VALUES

将生成 principal_id 列中的 NULL 值:

[
  {"object_id":3,"name":"sysrscols","type":"S ","principal_id":null},
  {"object_id":5,"name":"sysrowsets","type":"S ","principal_id":null},
  {"object_id":6,"name":"sysclones","type":"S ","principal_id":null}
]