带有列别名的 FOR JSON PATH
FOR JSON PATH 使你可以使用列别名控制输出 JSON 的格式:
SELECT top 3 object_id as id, name as [data.name], type as [data.type]
FROM sys.objects
FOR JSON PATH
列别名将用作键名。以点分隔的列别名(data.name 和 data.type)将作为嵌套对象生成。如果两列在点表示法中具有相同的前缀,则它们将在单个对象(本示例中的数据)中组合在一起:
[
{"id":3,"data":{"name":"sysrscols","type":"S "}},
{"id":5,"data":{"name":"sysrowsets","type":"S "}},
{"id":6,"data":{"name":"sysclones","type":"S "}}
]