onelson / jq-rs

Rust crate to provide programmatic access to `jq`.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Multiple json input

MarcAntoine-Arnaud opened this issue · comments

JQ is able to merge multiple json in one.

Is it possible to define a method like:
https://github.com/onelson/jq-rs/blob/master/src/jq.rs#L76

fn process_multiple(&mut self, source_values: Vec<JV>) -> Result<String> {
 ...
}

Is it simple a multiple call of jq_start with different inputs ?

Hi @MarcAntoine-Arnaud - interesting request. So, I suppose what you're looking for is essentially the same thing as jq_rs::compile() but without allocating a string per input.

I think essentially how I wrote the "compile and reuse" pattern is as you describe - calling jq_start for each input.

In jq proper, we're talking about something like:

jq . a.json b.json

just calling it with multiple input files, right?

I haven't done this before, so I wanted to check there's no magic to it.

Hello,

I have the same need. I think the purpose of this issue was to bind the slurp functionality of JQ https://stedolan.github.io/jq/manual/v1.6/#Invokingjq:

Instead of running the filter for each JSON object in the input, read the entire input stream into a large array and run the filter just once.

Ah, maybe I misunderstood. I thought @MarcAntoine-Arnaud was asking about something akin to the --stream flag instead of --slurp. Slurp sounds as though it would have the opposite impact on memory consumption for large inputs.

Maybe there should be an issue for each flag.

Slurp allows to merge all the inputs into one output according to a jq program

Yes, I think it would probably require an issue for each flag

Is

jq-rs/src/lib.rs

Lines 177 to 180 in 5a50b86

// During work on #4, #7, the parser test which allows us to avoid a memory
// error shows that an empty input just yields an empty response BUT our
// implementation would yield a parse error.
return Ok("".into());
a consequence of this issue? An empty input yields an empty output because the program is never run for any input, which should not be a special case.