Why did a JSON constructor turn an array into quoted text?
json_object encodes an ordinary text value as a string. A value supplied directly by json() can be embedded as a JSON structure.
SQLite example and interpretation
Passing the text [1,2] directly produces a string field. Wrapping valid input in json() produces a nested array that consumers can index.
SELECT json_object('tags','[1,2]'),json_object('tags',json('[1,2]'));Result [["{\"tags\":\"[1,2]\"}", "{\"tags\":[1,2]}"]]
中文
为什么构造 JSON 对象时数组变成了带引号的文字?
json_object 的普通文本值按字符串编码;直接来自 json() 的结果可按 JSON 结构嵌入。
SQLite 示例与适用条件
把标签串 [1,2] 直接放入字段会得到字符串;确认它是合法 JSON 后包装为 json() 才得到真正的数组。
SELECT json_object('tags','[1,2]'),json_object('tags',json('[1,2]'));结果 [["{\"tags\":\"[1,2]\"}", "{\"tags\":[1,2]}"]]