serde-query
provides a query language for Serde data model.
serde-query
is:
serde-query
can work with any serde-compatible formats.```rust use serde_query::{DeserializeQuery, Query};
struct Data { #[query(".commit.authors.[0]")] firstauthor: String, #[query(".hash")] hashvalue: u64, }
let document = serdejson::tostring(&serde_json::json!({ "commit": { "authors": ["Kou", "Kasumi", "Masaru"], "date": "2020-09-10", }, "hash": 0xabcd, }))?;
// You can use Query<T>
as a Deserialize
type for any Deserializer
// and convert the result to the desired type using From
/Into
.
let data: Data = serdejson::fromstr::
asserteq!(data.firstauthor, "Kou"); asserteq!(data.hashvalue, 0xabcd); ```
This library generates Rust types for each query segment (e.g., .commit
, .commit.message
, etc.), which may lead to binary bloat and longer compile time.
Licensed under either of
at your option.
Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in the work by you, as defined in the Apache-2.0 license, shall be dual licensed as above, without any additional terms or conditions.