json - JSON 指针中波浪号的用途

标签 json json-patch jsonpointer

JSON Pointer规范说明:

the characters '~' (%x7E) and '/' (%x2F) have special meanings in JSON Pointer



很清楚 '/' 的用途是什么,但我看不到波浪号有什么用途的迹象(只提到它需要转义以及如何转义)。

最佳答案

在 JSON 指针中,您需要使用 ~1编码你想要的 /作为路径中属性名称的一部分。正因为如此,~获得特殊含义作为转义序列的指示符,不再表示真正的波浪号。真正的波浪号表示为转义序列 ~0 .

换句话说(引用自 JSON Pointer 规范):

Evaluation of each reference token begins by decoding any escaped character sequence. This is performed by first transforming any occurrence of the sequence '~1' to '/', and then transforming any occurrence of the sequence '~0' to '~'. By performing the substitutions in this order, an implementation avoids the error of turning '~01' first into '~1' and then into '/', which would be incorrect (the string '~01' correctly becomes '~1' after transformation).



在此处查看 JSON 补丁测试可能会很有趣:https://github.com/json-patch/json-patch-tests/blob/master/spec_tests.json#L200 (搜索 ~)

关于json - JSON 指针中波浪号的用途,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31483170/

相关文章:

kubernetes - 修复 Argo CD 中的不同步警告 - 无法忽略可选的 `preserveUnknownFields` 字段

json - 从 Spring MVC Controller 返回 JSON 或 View

jquery菜鸟: cannot parse json

c# - 如何将 json-patch 应用于 .net core 中的纯 json?

java - 如何仅更新可能已为空的某些字段(使用 JSON 补丁)

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

javascript - 有什么方法可以使用 JSON 指针在侧 JSON 字符串中使用相对路径?

python - networkx - 将图转储到带有权重的 JSON 中

json - 名为 "id"的所有键的输出路径,其中值的类型为 "string"

json - 由于 json 指针,Sphinx 无法包含我的 JSON 定义文件