3. Syntax (语法)
3. Syntax (语法)
JSON Pointer 是一个 Unicode 字符串 (参见 [RFC4627], Section 3), 包含零个或多个引用标记 (reference tokens) 的序列, 每个标记前面都有一个 '/' (%x2F) 字符作为前缀。
因为字符 '' (%x7E) 和 '/' (%x2F) 在 JSON Pointer 中具有特殊含义, 所以当这些字符出现在引用标记中时, '' 需要被编码为 '~0', '/' 需要被编码为 '~1'。
JSON Pointer 的 ABNF 语法如下:
json-pointer = *( "/" reference-token )
reference-token = *( unescaped / escaped )
unescaped = %x00-2E / %x30-7D / %x7F-10FFFF
; %x2F ('/') and %x7E ('~') are excluded from 'unescaped'
escaped = "~" ( "0" / "1" )
; representing '~' and '/', respectively
如果 JSON Pointer 值不符合此语法, 则属于错误情况 (error condition) (参见 Section 7)。
注意, JSON Pointer 是以字符 (characters) 而非字节 (bytes) 来指定的。