Utiliser JSON Pointer (RFC 6901) en référence valeurs
JSON Pointer defines un chaîne syntax pour identifying un spécifique valeur en un JSON document utilisant slash-separated path tokens.
- 1
JSON Pointer (RFC 6901) uses "/" to separate path tokens and "~1" / "~0" to escape "/" and "~" in keys. For example, "/foo/bar" points to root.foo.bar. An empty string "" points to the root. It is the foundation for JSON Patch and JSON Schema.
- 2 Requêtes JSONPath →
Evaluate a JSON Pointer expression against a JSON document. Enter the pointer (e.g., "/users/0/name") and the JSON to extract the referenced value. This is useful for validation and data extraction.
- 3 Validateur JSON →
Valider 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 is simpler (only slash-separated paths, no filters or wildcards) and is standardized (RFC 6901). JSONPath (like $.store.book[*].author) is more expressive but not standardized. Use JSON Pointer for simple references and JSON Patch; use JSONPath for complex queries.
Questions fréquentes
- How do I escape special characters in JSON Pointer?
- Use "~1" for "/" and "~0" for "~" in path tokens. For example, to reference the key "a/b", use "/a~1b". The tilde is escaped first, then the slash — "~01" decodes to "~1", not "/".
- What is the empty JSON Pointer?
- The empty string "" refers to the entire document (the root). This is different from "/" which refers to a key named "" (empty string key). The distinction matters in JSON Patch operations.