{"id":15647774,"url":"https://github.com/chanced/jsonptr","last_synced_at":"2025-04-13T00:43:41.767Z","repository":{"id":41332281,"uuid":"495903467","full_name":"chanced/jsonptr","owner":"chanced","description":"JSON Pointer (RFC 6901) implementation for Rust","archived":false,"fork":false,"pushed_at":"2025-03-02T12:17:43.000Z","size":684,"stargazers_count":45,"open_issues_count":10,"forks_count":5,"subscribers_count":5,"default_branch":"main","last_synced_at":"2025-04-13T00:43:35.943Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"Rust","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/chanced.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":"LICENSE-APACHE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2022-05-24T16:27:44.000Z","updated_at":"2025-02-26T18:28:53.000Z","dependencies_parsed_at":"2024-08-07T01:43:38.499Z","dependency_job_id":"0d12d5bc-3cf4-4a67-919a-5837659f875f","html_url":"https://github.com/chanced/jsonptr","commit_stats":{"total_commits":143,"total_committers":7,"mean_commits":"20.428571428571427","dds":"0.29370629370629375","last_synced_commit":"bf648a4b438588cd975426b207f343397ab92b9e"},"previous_names":[],"tags_count":22,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/chanced%2Fjsonptr","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/chanced%2Fjsonptr/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/chanced%2Fjsonptr/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/chanced%2Fjsonptr/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/chanced","download_url":"https://codeload.github.com/chanced/jsonptr/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248650419,"owners_count":21139672,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-10-03T12:21:01.418Z","updated_at":"2025-04-13T00:43:41.743Z","avatar_url":"https://github.com/chanced.png","language":"Rust","funding_links":[],"categories":[],"sub_categories":[],"readme":"\u003cdiv class=\"rustdoc-hidden\"\u003e\n\n# jsonptr - JSON Pointers (RFC 6901) for Rust\n\n\u003c/div\u003e\n\n[\u003cimg alt=\"github\" src=\"https://img.shields.io/badge/github-chanced/jsonptr-62D1FC?style=for-the-badge\u0026labelColor=777\u0026logo=github\" height=\"21\"\u003e](https://github.com/chanced/jsonptr)\n[\u003cimg alt=\"crates.io\" src=\"https://img.shields.io/crates/v/jsonptr.svg?style=for-the-badge\u0026color=fc8d62\u0026logo=rust\" height=\"21\"\u003e](https://crates.io/crates/jsonptr)\n[\u003cimg alt=\"docs.rs\" src=\"https://img.shields.io/badge/docs.rs-jsonptr-f0f0f0?style=for-the-badge\u0026labelColor=777\u0026logo=docs.rs\" height=\"21\"\u003e](https://docs.rs/jsonptr)\n[\u003cimg alt=\"build status\" src=\"https://img.shields.io/github/actions/workflow/status/chanced/jsonptr/test.yml?branch=main\u0026style=for-the-badge\" height=\"21\"\u003e](https://github.com/chanced/jsonptr/actions?query=branch%3Amain)\n[\u003cimg alt=\"code coverage\" src=\"https://img.shields.io/codecov/c/github/chanced/jsonptr?style=for-the-badge\u0026color=CBB88D\" height=\"21\"\u003e](https://codecov.io/gh/chanced/jsonptr)\n\nJSON Pointers ([RFC 6901](https://datatracker.ietf.org/doc/html/rfc6901))\ndefines a string syntax for identifying a specific location within a JSON, or\nsimilar, document. This crate provides two types, [`Pointer`] and [`PointerBuf`]\n(akin to [`Path`] and [`PathBuf`]), for working with them abstractly.\n\nA pointer is composed of zero or more [`Token`]s, single segments which\nrepresent a field of an object or an [`index`] of an array, and are bounded by\neither `'/'` or the end of the string. Tokens are lightly encoded, where `'~'`\nis escaped as `\"~0\"` due to it signaling encoding and `'/'` is escaped as `\"~1\"`\nbecause `'/'` separates tokens and would split the token into two otherwise.\n\n[`Token`]s can be iterated over using either [`Tokens`], returned from the\n[`tokens`] method of a pointer or [`Components`], returned from the\n[`components`] method. The difference being that `Tokens` iterates over each\ntoken in the pointer, while `Components` iterates over [`Component`]s, which can\nrepresent the root of the document or a single token of the pointer.\n\nOperations [`resolve`], [`assign`] and [`delete`] are provided as traits with\ncorresponding methods on pointer types. Implementations of each trait are\nprovided for value types of the crates [`serde_json`] and [`toml`]. All\noperations are enabled by default but are gated by [feature\nflags](#feature-flags).\n\n## Usage\n\n### Parsing and General Usage\n\nTo parse a [`Pointer`] from a string, use either [`Pointer::parse`], for\npotentially fallible parsing, or the `const fn` `from_static` to produce a\n`\u0026'static Pointer` from a string that is known to be valid.\n\n```rust\nuse jsonptr::Pointer;\n\nlet ptr = Pointer::parse(\"/examples/0/name\").unwrap();\nlet static_ptr = Pointer::from_static(\"/examples/0/name\");\nassert_eq!(ptr, static_ptr);\n\nassert_eq!(ptr.get(1..).unwrap(), Pointer::parse(\"/0/name\").unwrap());\n\nlet parent = ptr.parent().unwrap();\nassert_eq!(parent, Pointer::parse(\"/examples/0\").unwrap());\n\nlet (token, remaining) = ptr.split_front().unwrap();\nassert_eq!(token.decoded(), \"examples\");\nassert_eq!(remaining, Pointer::parse(\"/0/name\").unwrap());\n```\n\n[`PointerBuf`]s can be parsed using [`PointerBuf::parse`] or constructed from an\niterator of [`Token`]s with the [`from_tokens`] method:\n\n```rust\nuse jsonptr::PointerBuf;\nlet mut buf = PointerBuf::parse(\"/examples/0/name\").unwrap();\n\nlet from_tokens = PointerBuf::from_tokens([\"examples\", \"0\", \"name\"]);\nassert_eq!(\u0026buf, \u0026from_tokens);\n\nbuf.push_front(\"pointer\");\nbuf.push_front(\"~\");\nbuf.push_back(\"/\");\nassert_eq!(buf.as_str(), \"/~0/pointer/examples/0/name/~1\");\n```\n\n### Token Iteration\n\nIterating over the tokens or components of a pointer:\n\n```rust\nuse jsonptr::{Pointer, Component, Token};\nlet ptr = Pointer::from_static(\"/path/to/value\");\n\n//  Using the `tokens` method:\nlet tokens: Vec\u003c_\u003e = ptr.tokens().collect();\nassert_eq!(tokens, vec![Token::new(\"path\"), Token::new(\"to\"), Token::new(\"value\")]);\n\n// Using the `components` method:\nlet mut components = ptr.components();\nassert_eq!(components.next(), Some(Component::Root));\nassert_eq!(components.next(), Some(Component::Token(Token::new(\"path\"))));\nassert_eq!(components.next(), Some(Component::Token(Token::new(\"to\"))));\nassert_eq!(components.next(), Some(Component::Token(Token::new(\"value\"))));\n```\n\n### Resolving Values\n\nTo get a value at the location of a pointer, use either the [`Resolve`] and\n[`ResolveMut`] traits or [`Pointer::resolve`] and [`Pointer::resolve_mut`]\nmethods. See the [`resolve`] mod for more information.\n\n```rust\nuse jsonptr::Pointer;\nuse serde_json::json;\n\nlet ptr = Pointer::parse(\"/foo/bar\").unwrap();\nlet data = json!({\"foo\": { \"bar\": 34 }});\nlet bar = ptr.resolve(\u0026data).unwrap();\nassert_eq!(bar, \u0026json!(34));\n```\n\n### Assigning Values\n\nValues can be set, with path expansion, using the either the [`Assign`] trait or\n[`Pointer::assign`]. See [`assign`] for more information.\n\n```rust\nuse jsonptr::Pointer;\nuse serde_json::json;\n\nlet ptr = Pointer::parse(\"/secret/universe\").unwrap();\nlet mut data = json!({\"secret\": { \"universe\": 42 }});\nlet replaced = ptr.assign(\u0026mut data, json!(34)).unwrap();\nassert_eq!(replaced, Some(json!(42)));\nassert_eq!(data, json!({\"secret\": { \"universe\": 34 }}));\n```\n\n### Deleting Values\n\nValues can be removed with the either the [`Delete`] trait or\n[`Pointer::delete`]. See [`delete`] for more information.\n\n```rust\nuse jsonptr::Pointer;\nuse serde_json::json;\n\nlet ptr = Pointer::parse(\"/secret/universe\").unwrap();\nlet mut data = json!({\"secret\": { \"life\": 42, \"universe\": 42, \"everything\": 42 }});\nlet deleted = ptr.delete(\u0026mut data);\nassert_eq!(deleted, Some(json!(42)));\nassert_eq!(data, json!({\"secret\": { \"life\": 42, \"everything\": 42 }}));\n```\n\n### Error Reporting\n\nAny error produced by function calls into methods of traits or types of this\ncrate can be converted into a [`Report`] which contains the original error\nand the [`String`] which failed to parse or the [`PointerBuf`] which failed to\nresolve or assign.\n\n```rust\n    use jsonptr::{Pointer, Diagnose};\n    let ptr_str = \"foo/bar\";\n    let err /* Result\u003c\u0026Pointer, Report\u003cParseError\u003e\u003e */ = Pointer::parse(ptr_str).diagnose(ptr_str).unwrap_err();\n    assert!(err.original().is_no_leading_slash());\n```\n\nIn the case of [`PointerBuf::parse`], the [`ParseError`] is always wrapped in a\n[`Report`] so that the input `String` is not dropped.\n\n```rust\n    use jsonptr::{PointerBuf};\n    let ptr_str = \"foo/bar\";\n    let err /* Result\u003c\u0026PointerBuf, Report\u003cParseError\u003e\u003e */ = PointerBuf::parse(ptr_str).unwrap_err();\n    assert!(err.original().is_no_leading_slash());\n```\n\n## Feature Flags\n\n|    Flag     | Description                                                                                                                               | Enables         | Default |\n| :---------: | ----------------------------------------------------------------------------------------------------------------------------------------- | --------------- | :-----: |\n|   `\"std\"`   | Implements `std::error::Error` for error types                                                                                            |                 |    ✓    |\n|  `\"serde\"`  | Enables [`serde`] support for types                                                                                                       |                 |    ✓    |\n|  `\"json\"`   | Implements ops for [`serde_json::Value`]                                                                                                  | `\"serde\"`       |    ✓    |\n|  `\"toml\"`   | Implements ops for [`toml::Value`]                                                                                                        | `\"std\"`, `toml` |         |\n| `\"assign\"`  | Enables the [`assign`] module and related pointer methods, providing a means to assign a value to a specific location within a document   |                 |    ✓    |\n| `\"resolve\"` | Enables the [`resolve`] module and related pointer methods, providing a means to resolve a value at a specific location within a document |                 |    ✓    |\n| `\"delete\"`  | Enables the [`delete`] module and related pointer methods, providing a means to delete a value at a specific location within a document   | `\"resolve\"`     |    ✓    |\n| `\"miette\"`  | Enables integration with [`miette`](https://docs.rs/miette) for error reporting                                                           | `\"std\"`         |         |\n\n\u003cdiv class=\"rustdoc-hidden\"\u003e\n\n## License\n\nLicensed under either of\n\n-   Apache License, Version 2.0\n    ([LICENSE-APACHE](LICENSE-APACHE) or http://www.apache.org/licenses/LICENSE-2.0)\n-   MIT license\n    ([LICENSE-MIT](LICENSE-MIT) or http://opensource.org/licenses/MIT)\n\nat your convenience.\n\n## Contribution\n\nContributions and feedback are always welcome and appreciated. If you find an\nissue, please open a ticket or a pull request.\n\nUnless you explicitly state otherwise, any contribution intentionally submitted\nfor inclusion in the work by you, as defined in the Apache-2.0 license, shall be\ndual licensed as above, without any additional terms or conditions.\n\n[LICENSE-APACHE]: LICENSE-APACHE\n[LICENSE-MIT]: LICENSE-MIT\n\n\u003c/div\u003e\n\n[`Pointer::components`]: https://docs.rs/jsonptr/latest/jsonptrstruct.Pointer.html#method.components\n[`Pointer::tokens`]: https://docs.rs/jsonptr/latest/jsonptrstruct.Pointer.html#method.tokens\n[`Pointer`]: https://docs.rs/jsonptr/latest/jsonptr/struct.Pointer.html\n[`Pointer::parse`]: https://docs.rs/jsonptr/latest/jsonptr/struct.Pointer.html#method.parse\n[`Pointer::resolve`]: https://docs.rs/jsonptr/latest/jsonptr/struct.Pointer.html#method.resolve\n[`Pointer::resolve_mut`]: https://docs.rs/jsonptr/latest/jsonptr/struct.Pointer.html#method.resolve_mut\n[`Pointer::assign`]: https://docs.rs/jsonptr/latest/jsonptr/struct.Pointer.html#method.assign\n[`Pointer::delete`]: https://docs.rs/jsonptr/latest/jsonptr/struct.Pointer.html#method.delete\n[`PointerBuf::parse`]: https://docs.rs/jsonptr/latest/jsonptr/struct.PointerBuf.html#method.parse\n[`from_tokens`]: https://docs.rs/jsonptr/latest/jsonptr/struct.PointerBuf.html#method.from_tokens\n[`PointerBuf`]: https://docs.rs/jsonptr/latest/jsonptr/struct.PointerBuf.html\n[`Token`]: https://docs.rs/jsonptr/latest/jsonptr/struct.Token.html\n[`Tokens`]: https://docs.rs/jsonptr/latest/jsonptr/struct.Tokens.html\n[`Components`]: https://docs.rs/jsonptr/latest/jsonptr/struct.Components.html\n[`Component`]: https://docs.rs/jsonptr/latest/jsonptr/enum.Component.html\n[`index`]: https://docs.rs/jsonptr/latest/jsonptr/index/index.html\n[`tokens`]: https://docs.rs/jsonptr/latest/jsonptr/struct.Pointer.html#method.tokens\n[`components`]: https://docs.rs/jsonptr/latest/jsonptr/struct.Pointer.html#method.components\n[`resolve`]: https://docs.rs/jsonptr/latest/jsonptr/resolve/index.html\n[`assign`]: https://docs.rs/jsonptr/latest/jsonptr/assign/index.html\n[`delete`]: https://docs.rs/jsonptr/latest/jsonptr/delete/index.html\n[`Resolve`]: https://docs.rs/jsonptr/latest/jsonptr/resolve/trait.Resolve.html\n[`ResolveMut`]: https://docs.rs/jsonptr/latest/jsonptr/resolve/trait.ResolveMut.html\n[`Assign`]: https://docs.rs/jsonptr/latest/jsonptr/assign/trait.Assign.html\n[`Delete`]: https://docs.rs/jsonptr/latest/jsonptr/delete/trait.Delete.html\n[`serde`]: https://docs.rs/serde/1.0/serde/index\n[`serde_json`]: https://docs.rs/serde_json/1.0/serde_json/enum.Value.html\n[`serde_json::Value`]: https://docs.rs/serde_json/1.0/serde_json/enum.Value.html\n[`toml`]: https://docs.rs/toml/0.8/toml/enum.Value.html\n[`toml::Value`]: https://docs.rs/toml/0.8/toml/enum.Value.html\n[`Path`]: https://doc.rust-lang.org/std/path/struct.Path.html\n[`PathBuf`]: https://doc.rust-lang.org/std/path/struct.PathBuf.html\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fchanced%2Fjsonptr","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fchanced%2Fjsonptr","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fchanced%2Fjsonptr/lists"}