Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/greyblake/jsonpath-rs
JSONPath for Rust
https://github.com/greyblake/jsonpath-rs
filter json json-data json-parser jsonpath rust rust-lang rust-library traverse xpath
Last synced: 2 months ago
JSON representation
JSONPath for Rust
- Host: GitHub
- URL: https://github.com/greyblake/jsonpath-rs
- Owner: greyblake
- License: mit
- Created: 2017-12-28T00:06:24.000Z (about 7 years ago)
- Default Branch: master
- Last Pushed: 2018-09-13T21:04:17.000Z (over 6 years ago)
- Last Synced: 2024-10-13T13:25:34.742Z (3 months ago)
- Topics: filter, json, json-data, json-parser, jsonpath, rust, rust-lang, rust-library, traverse, xpath
- Language: Rust
- Size: 89.8 KB
- Stars: 37
- Watchers: 3
- Forks: 6
- Open Issues: 7
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# JSONPath for Rust
The library is in hard development stage.
[![Build Status](https://travis-ci.org/greyblake/jsonpath-rs.svg?branch=master)](https://travis-ci.org/greyblake/jsonpath-rs)
## Example
```rust
extern crate jsonpath;
extern crate serde_json;use jsonpath::Selector;
use serde_json::Value;fn main() {
let jsondoc = r#"
{
"books": [
{
"title": "Der schwarze Obelist",
"author": "Erich Maria Remarque"
},
{
"title": "Le mur",
"author": "Jean-Paul Sartre"
}
]
}
"#;// Parse JSON document
let json: Value = serde_json::from_str(jsondoc).unwrap();// Create a JSONPath selector
let selector = Selector::new("$.books.*.title").unwrap();// Apply the selector to the JSON and convert Vec<&Value> into Vec<&str>
let titles: Vec<&str> = selector.find(&json)
.map(|t| t.as_str().unwrap())
.collect();assert_eq!(titles, vec!["Der schwarze Obelist", "Le mur"]);
}
```## Roadmap
* [ ] Operators:
* [x] `$` - root element
* [x] `.` - named child element
* [x] `*` - wildcard (any child item)
* [x] `[]` - indexed element in array
* [x] `[:]` - slice
* [x] `[:]` - slice (to)
* [x] `[:]` - slice (from)
* [ ] Handy test helpers
* [ ] Good integration test coverage
* [ ] Benchmarks
* [ ] Refactor
* [ ] Improve error messages
* [ ] Review unwraps
* [ ] Review the public API (rename Selector -> Path ?)
* [ ] Publish a new version
* [ ] Mutable iterator
* [x] Support filters
* [x] `[?()]` - Filter expression. Expression must evaluate to a boolean value.
* [x] `@` - current element
* [x] operator `==`
* [x] operator `!=`
* [x] operator `>`
* [x] operator `<`
* [x] operator `>=`
* [x] operator `<=`
* [ ] operator `=~`
* [x] filter comparison with expression on the right side `[?( )]`
* [x] string
* [x] float
* [x] integer
* [x] array of string
* [ ] array of float
* [ ] array of number
* [ ] sub script expression `()`
* [ ] and operator `&&`
* [ ] or operator `||`## Supported Rust versions
Jsonpath requires rust version 1.26 or higher.
## License
[MIT](https://github.com/greyblake/jsonpath-rs/blob/master/LICENSE) © [Sergey Potapov](http://greyblake.com)
## Contributors
- [greyblake](https://github.com/greyblake) Sergey Potapov - creator, maintainer.
- [MarcAntoine-Arnaud](https://github.com/MarcAntoine-Arnaud) Marc-Antoine ARNAUD - filters support