Use JSON Pointer (RFC 6901) 到参考 values
JSON Pointer defines 字符串 syntax 为 identifying 特定值 在 JSON document using slash-separated 路径 tokens.
- 1
JSON Pointer (RFC 6901) 我们 "/" 到 separate 路径 tokens 和 "~1" / "~0" 到 escape "/" 和 "~" 在关键. 为示例, "/foo/bar" points 到根.foo.bar. 空字符串 "" points 到根. 它是 foundation 为 JSON Patch 和 JSON Schema.
- 2 JSONPath 查询器 →
Evaluate JSON Pointer 表达式针对 JSON document. Enter pointer (e.g., "/users/0/name") 和 JSON 到提取 referenced 值. 此是 useful 为 validation 和数据 extraction.
- 3 JSON 验证器 →
验证 the JSON document before applying the pointer. A pointer to a non-existent path returns null or raises an error depending on the implementation. Validate first to get a clear error message.
- 4
JSON Pointer vs JSONPath: JSON Pointer 是 simpler (仅 slash-separated paths, 否 filters 或 wildcards) 和是 standardized (RFC 6901). JSONPath (like $.存储.book[*].作者) 是更多 expressive 但不 standardized. Use JSON Pointer 为简单参考和 JSON Patch; use JSONPath 为复杂 queries.
常见问题
- 如何 I escape 特殊 characters 在 JSON Pointer?
- Use "~1" 为 "/" 和 "~0" 为 "~" 在路径 tokens. 为示例, 到参考键 "/b", use "/~1b". tilde 是 escaped 第一, 然后 slash — "~01" decodes 到 "~1", 不 "/".
- 什么是 空 JSON Pointer?
- 空字符串 "" refers 到整个 document ( 根). 此是 不同从 "/" 哪个 refers 到键 named "" (空字符串键). distinction matters 在 JSON Patch 操作.