Skip to content

Commit

Permalink
Update src/jnv.rs
Browse files Browse the repository at this point in the history
Co-authored-by: ynqa <un.pensiero.vano@gmail.com>
  • Loading branch information
edy555 and ynqa committed May 4, 2024
1 parent 14f6f6c commit 32f6192
Showing 1 changed file with 6 additions and 11 deletions.
17 changes: 6 additions & 11 deletions src/jnv.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,17 +36,12 @@ mod keymap;
/// An `anyhow::Result` wrapping a vector of `serde_json::Value`. On success, it contains the parsed
/// JSON data. On failure, it contains an error detailing what went wrong during parsing.
fn deserialize_json(json_str: &str, limit_length: Option<usize>) -> anyhow::Result<Vec<serde_json::Value>> {
match limit_length {
Some(l) => Deserializer::from_str(json_str)
.into_iter::<serde_json::Value>()
.take(l)
.map(|res| res.map_err(anyhow::Error::from))
.collect::<anyhow::Result<Vec<serde_json::Value>>>(),
None => Deserializer::from_str(json_str)
.into_iter::<serde_json::Value>()
.map(|res| res.map_err(anyhow::Error::from))
.collect::<anyhow::Result<Vec<serde_json::Value>>>(),
}
let deserializer = Deserializer::from_str(json_str).into_iter::<serde_json::Value>();
let results = match limit_length {
Some(l) => deserializer.take(l).collect::<Result<Vec<_>, _>>(),
None => deserializer.collect::<Result<Vec<_>, _>>(),
};
results.map_err(anyhow::Error::from)
}

fn run_jq(query: &str, json_stream: &[serde_json::Value]) -> anyhow::Result<Vec<String>> {
Expand Down

0 comments on commit 32f6192

Please sign in to comment.