# jetro
[](https://docs.rs/jetro)
[](https://jetro.io)
![GitHub](https://img.shields.io/github/license/mitghi/jetro)
Jetro is a library which provides a custom DSL for transforming, querying and comparing data in JSON format. It is easy to use and extend.
Jetro has minimal dependency, the traversal and eval algorithm is implemented on top of [serde_json](https://serde.rs).
Jetro can be used inside Web Browser by compiling down to WASM. [Clone it](https://github.com/mitghi/jetroweb) and give it a shot.
Jetro can be used in command line using [Jetrocli](https://github.com/mitghi/jetrocli).
Jetro combines access path with functions which operate on values matched within the pipeline. Access path uses `/` as separator similar to structure of URI, the start of access path should denote whether the access starts from root by using `>`, it is possible to traverse from root in nested paths by using `<`.
Jetro expressions support line breaks and whitespace, the statements can be broken up into smaller parts.
By convention, functions are denoted using `#` operator. Functions can be composed.
| Function | Action |
| -------- | ------ |
| #pick('string' \| expression, ...) [ as \| as* 'binding_value' ] | Select a key from an object, bind it to a name, select multiple sub queries to create new object |
| #head | Head of the list|
| #tail | Tail of the list |
| #keys | Keys associated with an object |
| #values | Values associated with an object |
| #reverse | Reverse the list |
| #min | Min value of numbers |
| #max | Max value of numbers |
| #all | Whether all boolean values are true |
| #sum | Sum of numbers |
| #formats('format with placeholder {} {}', 'key_a', 'key_b') [ -> \| ->* 'binding_value' ] | Insert formatted key:value into object or return it as single key:value |
| #filter('target_key' (>, <, >=, <=, ==, ~=, !=) (string, boolean, number)) | Perform Filter on list |
| #map(x: x.y.z \| x.y.z.some_method())| Map each item in a list with the given lambda |
| #zip | Zip two or more arrays together |
```rust
let data = serde_json::json!({
"name": "mr snuggle",
"some_entry": {
"some_obj": {
"obj": {
"a": "object_a",
"b": "object_b",
"c": "object_c",
"d": "object_d"
}
}
}
});
let mut values = Path::collect(data, ">/..obj/#pick('a','b')");
#[derive(Serialize, Deserialize)]
struct Output {
a: String,
b: String,
}
let output: Option