valq   ![Docs.rs shield] ![crates.io shield]

valq provides a macro for querying and extracting value from structured data in very concise manner, like the JavaScript syntax.

Look & Feel:

```rust use serdejson::Value; use valq::queryvalue;

let j: Value = ...; let deepval: Option<&Value> = queryvalue!(j.path.to.value.at.deep); ```

For now, there is only single macro exported: query_value.

query_value macro

A macro for querying inner value of structured data.

Basic Usage

``rust // get fieldfoofrom JSON objectobj` let foo = query_value!(obj.foo);

// get nested field bar inside object foo in JSON object obj let bar = query_value!(obj.foo.bar);

// get head of JSON array 'arr' let head = query_value!(arr[0]);

// get head of nested JSON array arr in JSON object obj let head = query_value!(obj.arr[0]);

// more complex example! let abyss = query_value!(obj.path.to.matrix[0][1].abyss); ```

Converting to Specified Type

``rust // try to convert extracted value tou64byasu64()method on that value. // results inNone` in case of type mismatch let foou64: Option = query_value!(obj.foo -> u64)

// in case of mutable reference extraction (see below), as_xxx_mut() method will be used. let arrvec: Option<&mut Vec> = queryvalue!(mut obj.arr -> array) ```

Extracting Mutable Reference to Inner Value

```rust use serde_json::{json, Value}

let mut obj = json!({"foo": { "bar": { "x": 1, "y": 2 }}}); { // prefixed mut means extracting mutable reference let bar: &mut Value = queryvalue!(mut obj.foo.bar).unwrap(); *bar = json!({"x": 100, "y": 200}); } asserteq!(queryvalue!(obj.foo.bar.x -> u64), Some(100)); asserteq!(query_value!(obj.foo.bar.y -> u64), Some(200)); ```