| Crates.io | jsonptr-lite |
| lib.rs | jsonptr-lite |
| version | 0.1.1 |
| created_at | 2025-11-29 23:13:15.413607+00 |
| updated_at | 2025-11-29 23:13:15.413607+00 |
| description | Tiny JSON Pointer lookups for serde_json::Value |
| homepage | https://github.com/thegreatbey/jsonptr-lite |
| repository | https://github.com/thegreatbey/jsonptr-lite |
| max_upload_size | |
| id | 1957644 |
| size | 27,216 |
Tiny JSON Pointer lookups for serde_json::Value (RFC 6901), dependency-light and fast to use.
ptr(&Value, &str) -> Option<&Value>~1 → /, ~0 → ~None for invalid pointers or missing pathsuse serde_json::{json, Value};
use jsonptr_lite::ptr;
let v = json!({ "a": { "b": 3 }});
assert_eq!(ptr(&v, "/a/b").and_then(Value::as_i64), Some(3));
ptr_mut example
use serde_json::{json, Value};
use jsonptr_lite::{ptr, ptr_mut};
//change nested object value by pointer
let mut v = json!({"a":{"b":0},"items":[1,2,3]});
*ptr_mut(&mut v, "/a/b").unwrap() = json!(42);
assert_eq!(ptr(&v, "/a/b").and_then(Value::as_i64), Some(42));
//change array element by pointer
*ptr_mut(&mut v, "/items/1").unwrap() = json!(9);
assert_eq!(ptr(&v, "/items/1").and_then(Value::as_i64), Some(9));
Arrays and escapes:
use serde_json::{json, Value};
use jsonptr_lite::ptr;
let v = json!({
"items": [10, 20, 30],
"a/b": 7,
"x~y": 9
});
assert_eq!(ptr(&v, "/items/1").and_then(Value::as_i64), Some(20));
assert_eq!(ptr(&v, "/a~1b").and_then(Value::as_i64), Some(7)); // "/" in key
assert_eq!(ptr(&v, "/x~0y").and_then(Value::as_i64), Some(9)); // "~" in key
Licensed under either of
at your option.