json - JSON Patch RFC 中的波浪号转义应该如何操作?

标签 json patch json-patch rfc6902

引用https://www.rfc-editor.org/rfc/rfc6902#appendix-A.14 :

A.14. ~ Escape Ordering

An example target JSON document:

{
  "/": 9,
  "~1": 10
}

A JSON Patch document:

[
  {"op": "test", "path": "/~01", "value": 10}
]

The resulting JSON document:

{
  "/": 9,
  "~1": 10
}

我正在编写此 RFC 的实现,但我陷入了困境。这是要实现什么目标,它应该如何工作?

假设第一部分的答案是“允许引用包含/s 的 json 键名称”,您会怎么做?

最佳答案

~字符是JSON指针中的关键字。因此,我们需要将其“编码”为~0。引用jsonpatch.com ,

If you need to refer to a key with ~ or / in its name, you must escape the characters with ~0 and ~1 respectively. For example, to get "baz" from { "foo/bar~": "baz" } you’d use the pointer /foo~1bar~0

本质上,

[
  {"op": "test", "path": "/~01", "value": 10}
]

解码后的结果

[
  {"op": "test", "path": "/~1", "value": 10}
]

关于json - JSON Patch RFC 中的波浪号转义应该如何操作?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24419391/

相关文章:

Java 中的 JSON 补丁请求验证

php - json类型字段的Laravel数据库在返回值时添加“

sql - 如何使用 `jsonb_build_object` 创建带有聚合函数和动态键值的嵌套 JSON 返回

ruby-on-rails - 如何将补丁应用到 ruby​​ on rails?

linux - buildroot : predefs. h header 错误

java - 在不知道 JSON 结构的情况下在 Java 中解析嵌套的 JSON?

c# - 如何在不反序列化整个 JSON 文件的情况下仅解析特定对象?

php - 使用 CodeIgniter 写入 JSON 文件

magento - Magento 1.7.2通过SSH的安全补丁错误

Spring Data Rest - PATCH Postgres jsonb 字段