How do you append one JSON tag while keeping existing tags?

Using [#] in a json_set path targets the slot beyond the current array end and returns updated JSON text.

SQLite example and interpretation

Append public to a record already marked reviewed. Replaying the expression appends again, so check membership first for idempotent updates.

SELECT json_set('["reviewed"]','$[#]','public');

Result [["[\"reviewed\",\"public\"]"]]

中文

怎样在保留旧标签的同时添加一个 JSON 数组元素?

在 json_set 路径中使用 [#] 可定位数组末尾后的插入位置,函数返回新的 JSON 文本。

SQLite 示例与适用条件

已有 reviewed 标签的记录再加 public。重复执行仍会再追加一次,需要幂等语义时应先检测已有标签。

SELECT json_set('["reviewed"]','$[#]','public');

结果 [["[\"reviewed\",\"public\"]"]]

References / 参考来源

Keep reading / 继续阅读