gpt4 book ai didi

arrays - 在单个 JSON Patch 操作中向数组添加多个值?

转载 作者:行者123 更新时间:2023-12-04 11:15:18 51 4
gpt4 key购买 nike

我有一个像这样的 json 对象:

{
"content" : [
{
"id" : 54
"foo" : "bar"
},
{
"id" : 43
"foo" : "bar"
},
{
"id" : 76
"foo" : "bar"
}
]
}

如果我想向内容数组添加多个项目(顺序无关紧要),我可以使用带有单行/操作的 json 补丁添加到它吗?
{ "op": "add", "path": "/content/-", "value": [
{
"id" : 34
"foo" : "bar"
},
{
"id" : 23
"foo" : "bar"
},
{
"id" : 87
"foo" : "bar"
}
]
}

或者我是否必须为每个要添加的对象添加一行?

编辑:要清楚我想追加,而不是替换内容。

最佳答案

不幸的是,这似乎(还?)不可能......正如 Json Patch 规范所述:
https://tools.ietf.org/html/rfc6902#section-4.1

The "add" operation performs one of the following functions, depending upon what the target location references:

  • If the target location specifies an array index, a new value isinserted into the array at the specified index.

  • If the target location specifies an object member that does notalready exist, a new member is added to the object.

  • If the target location specifies an object member that doesexist, that member's value is replaced.

关于arrays - 在单个 JSON Patch 操作中向数组添加多个值?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59849760/

51 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com