pub struct Jq { /* private fields */ }Expand description
A wrapper for the jq command.
This can be used to transform a Value using a jq expression.
§Example
use dts_core::jq::Jq;
use serde_json::json;
let value = json!([5, 4, 10]);
let jq = Jq::new()?;
let result = jq.process("map(select(. > 5))", &value)?;
assert_eq!(result, json!([10]));Implementations§
Source§impl Jq
impl Jq
Sourcepub fn new() -> Result<Jq>
pub fn new() -> Result<Jq>
Creates a new Jq instance.
§Errors
If the jq executable cannot be found in the PATH or is invalid an error is returned.
Sourcepub fn with_executable<P>(executable: P) -> Result<Jq>
pub fn with_executable<P>(executable: P) -> Result<Jq>
Creates a new Jq instance using the provided executable.
§Errors
If executable cannot be found in PATH, does not exist (if absolute) or is invalid an
error is returned.
Sourcepub fn process(&self, expr: &str, value: &Value) -> Result<Value>
pub fn process(&self, expr: &str, value: &Value) -> Result<Value>
Processes a Value using the provided jq expression and returns the result.
§Errors
Error::Ioif spawningjqfails or if there are other I/O errors.Error::Jsonif the data returned byjqcannot be deserialized.Error::Messageon any other error.
Trait Implementations§
Auto Trait Implementations§
impl Freeze for Jq
impl RefUnwindSafe for Jq
impl Send for Jq
impl Sync for Jq
impl Unpin for Jq
impl UnwindSafe for Jq
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
Converts
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
Converts
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more