Why do positions shift when removing several JSON array entries?
json_remove applies paths from left to right. Each later path addresses the already modified document.
SQLite example and interpretation
To remove the original first and third items, delete the larger index first so the earlier edit cannot renumber the later target.
SELECT json_remove('["A","B","C","D"]','$[2]','$[0]');Result [["[\"B\",\"D\"]"]]
中文
一次删除多个 JSON 数组位置时,为什么索引会移动?
json_remove 按给定次序应用各路径,每次删除后,后续路径面对的是修改后的文档。
SQLite 示例与适用条件
若目标是删除原数组第 1 和第 3 项,从较大的下标开始可避免前一次删除使后续位置偏移。
SELECT json_remove('["A","B","C","D"]','$[2]','$[0]');结果 [["[\"B\",\"D\"]"]]