如果我有一个包含任意有效 JSON 文档的列的表,我可以将该文档嵌入到返回 JSON 的查询中,而不是作为字符串?
例如:
CREATE TABLE #Example (Name nvarchar(50) not null, Document nvarchar(max) not null);
INSERT INTO #Example VALUES
('Document 1', '{ "a": "a" }'),
('Document 2', '{ "b": "b" }');
SELECT *
FROM #Example
FOR JSON AUTO;
实际输出:
[
{
"Name":"Document 1",
"Document":"{ \"a\": \"a\" }"
},
{
"Name":"Document 2",
"Document":"{ \"b\": \"b\" }"
}
]
期望的输出(注意解析后的值Document
已经嵌入):
[
{
"Name":"Document 1",
"Document": { "a": "a" }
},
{
"Name":"Document 2",
"Document": { "b": "b" }
}
]