你能在 JSON 中嵌入 "commands" 吗?
Can you embed "commands" in JSON?
我有一些 JSON(我们称它为 json1
),我想将它与其他一些 JSON(json2
)结合起来。我不只是想合并或附加数据,我还希望能够通过在 json2
中嵌入“命令”来从 json1
中删除数据。
例子
json1 = {
"a": 1,
"b": "xyz",
"c": ["foo", "bar"]
}
json2 = {
"b": "hello world",
"d": 4,
"c": ["-foo", "+foobar"],
}
output = combine(json1, json2)
// Expected result from the fictional "combine()" method
output = {
"a": 1,
"b": "hello world",
"c": ["bar", "foobar"],
"d": 4
}
当然我可以想出我自己的语法和逻辑,但我很好奇是否有任何现有技术可以使用 JSON?
来操纵 JSON
免责声明:我不是在问 recommendations for books, tools, software libraries (or more). I merely have a practical, answerable problem that is unique to software development pertaining to a specific programming problem and am asking about software tools commonly used by programmers, or possibly a software algorithm。哎呀
使用 jsonpatch,您的示例将转换为 JSON Patch
类似于:
[
{ "op": "replace", "path": "/b", "value": "hello world" },
{ "op": "add", "path": "/d", "value": 4 },
{ "op": "replace", "path": "/c/0", "value": "foobar"}
]
我有一些 JSON(我们称它为 json1
),我想将它与其他一些 JSON(json2
)结合起来。我不只是想合并或附加数据,我还希望能够通过在 json2
中嵌入“命令”来从 json1
中删除数据。
例子
json1 = {
"a": 1,
"b": "xyz",
"c": ["foo", "bar"]
}
json2 = {
"b": "hello world",
"d": 4,
"c": ["-foo", "+foobar"],
}
output = combine(json1, json2)
// Expected result from the fictional "combine()" method
output = {
"a": 1,
"b": "hello world",
"c": ["bar", "foobar"],
"d": 4
}
当然我可以想出我自己的语法和逻辑,但我很好奇是否有任何现有技术可以使用 JSON?
来操纵 JSON免责声明:我不是在问 recommendations for books, tools, software libraries (or more). I merely have a practical, answerable problem that is unique to software development pertaining to a specific programming problem and am asking about software tools commonly used by programmers, or possibly a software algorithm。哎呀
使用 jsonpatch,您的示例将转换为 JSON Patch
类似于:
[
{ "op": "replace", "path": "/b", "value": "hello world" },
{ "op": "add", "path": "/d", "value": 4 },
{ "op": "replace", "path": "/c/0", "value": "foobar"}
]