Fix --stream-errors w/o --stream, and doc+test (close #2748)

This commit is contained in:
Nicolas Williams authored and Nico Williams committed 2023-07-23 03:33:28 -05:00
1 parent 123c780607
commit f64ef1a7d7
4 files changed
+25 -1

No files matched your search

+10
View File
@@ -130,6 +130,16 @@ sections:
conjunction with filtering and the `reduce` and `foreach` syntax
to reduce large inputs incrementally.
* `--stream-errors`:
Like `--stream`, but invalid JSON inputs yield array calues
where the first element is the error and the second is a path.
For example, `["a",n]` produces ["Invalid literal at line 1,
column 9",[1]]`.
Implies `--stream`. Invalid JSON inputs produce no error values
when `--stream` without `--stream-errors`.
* `--slurp`/`-s`:
Instead of running the filter for each JSON object in the
Generated
+9
View File
@@ -73,6 +73,15 @@ Parse the input in streaming fashion, outputting arrays of path and leaf values
This is useful for processing very large inputs\. Use this in conjunction with filtering and the \fBreduce\fR and \fBforeach\fR syntax to reduce large inputs incrementally\.
.
.TP
\fB\-\-stream\-errors\fR:
.
.IP
Like \fB\-\-stream\fR, but invalid JSON inputs yield array calues where the first element is the error and the second is a path\. For example, \fB["a",n]\fR produces ["Invalid literal at line 1, column 9",[1]]`\.
.
.IP
Implies \fB\-\-stream\fR\. Invalid JSON inputs produce no error values when \fB\-\-stream\fR without \fB\-\-stream\-errors\fR\.
.
.TP
\fB\-\-slurp\fR/\fB\-s\fR:
.
.IP
+1 -1
View File
@@ -465,7 +465,7 @@ int main(int argc, char* argv[]) {
continue;
}
if (isoption(argv[i], 0, "stream-errors", &short_opts)) {
parser_flags |= JV_PARSE_STREAM_ERRORS;
parser_flags |= JV_PARSE_STREAMING | JV_PARSE_STREAM_ERRORS;
continue;
}
if (isoption(argv[i], 'e', "exit-status", &short_opts)) {
+5
View File
@@ -180,6 +180,11 @@ $VALGRIND $Q $JQ -c '. as $d|path(..) as $p|$d|getpath($p)|select((type|. != "ar
$VALGRIND $Q $JQ --stream -c '.|select(length==2)' < "$JQTESTDIR/torture/input0.json" > $d/out1
diff $d/out0 $d/out1
printf '["Unfinished JSON term at EOF at line 1, column 1",[0]]\n' > $d/expected
printf '[' | $VALGRIND $Q $JQ --stream-errors -c . > $d/out 2>&1
diff $d/out $d/expected
## XXX This test can be moved to tests/all.test _now_
clean=false
if which seq > /dev/null 2>&1; then