On Windows, $ENV and env were built from environ, which the C library
fills in the ANSI code page, so names and values outside of it were
mangled before jq saw them.
Build the environment object from GetEnvironmentStringsW() and convert
each entry from UTF-16 to UTF-8, skipping the hidden per-drive working
directory entries starting with '=' as environ does, and skipping any
entry that fails to convert. env and $ENV now share a single reader,
get_env() in util.c, which also skips malformed entries without '='
in both, instead of env mapping them to null and $ENV deleting an
existing variable of that name. Other platforms still read environ.
On Windows, jq could not open files whose paths exceed MAX_PATH (260
characters), even with LongPathsEnabled set, because the executable did
not declare longPathAware in its application manifest.
Embed an application manifest in jq.exe through a resource compiled
with windres, detected by configure for native Windows hosts. The
manifest keeps the asInvoker and supportedOS entries of the MinGW
default manifest it replaces and adds longPathAware. It uses a non-zero
resource language so that the linker drops the default manifest. Add a
PowerShell test that reads a file through a path longer than MAX_PATH
in the Windows CI jobs.
Co-authored-by: BaalEvan <baalevan@outlook.com>
When a regex had several groups with the same name, a later group that
did not take part in the match overwrote an earlier one that did, so
capture returned null and sub interpolated null instead of the matched
text.
Build the capture object in capture/2 and in the sub reducer by adding
a one-key object for each named group, keeping the value already stored
for that name when the current group did not match. The last group of
each name that took part in the match now wins, empty-string matches
are kept, and the value stays null only when no group of that name
matched. Key order is unchanged. Add a regression test for capture, sub
and gsub.
With --seq, an RS inside a string or after whitespace in an open array
or object did not report the text as truncated; it was dropped silently
or reported with the wrong message.
Report the text as truncated when an RS arrives inside a string, and
apply the whitespace exception of the truncation check only to top-level
values, so that an RS after `[1, ` reports a truncated value.
Extending an array slice by assigning past its end filled the gap with
elements of the original array that the slice had cut off.
Fill the gap from the logical end of the slice, releasing the hidden
values it overwrites, so that `.[:3] | .[5] = true` pads the slice
with nulls.
When the size of a file was an exact multiple of the read buffer,
the parser was never told that the input had ended.
Pass the final empty read to the parser so that it finalizes at EOF.
This makes `--slurpfile` and JSON data imports keep a trailing number
or literal and report truncated JSON as an error, regardless of the
file size.
Numbers, null, true and false own no memory, but jv_free() still ran
its whole loop for them and ended with free(NULL).
Return at the top of jv_free() for values without a payload, using the
same test as jv_copy(), and skip freeing the pending list when none was
allocated. This makes interpreter loops such as `reduce range(N) as $i
(0; .+$i)` about 15-19% faster, and parsing number-heavy input 3-8%
faster.
Write the indentation from a static run of spaces or tabs, one chunk
at a time, rather than one character at a time. This makes
pretty-printing deeply nested input several times faster, especially
with wider indentation such as `--indent 7`. Output is unchanged.
When the last text of a --seq input had a parse error, the parser
reached EOF while skipping to the next RS and reported the same text
again as unfinished abandoned text.
Remember that the skipped text was already reported, so that the input
ends quietly at EOF. Text before the first RS is still reported as
abandoned.
Converting a number literal to a double first rounded it to 17
significant digits, so a literal near the midpoint of two doubles
could be rounded twice in the wrong direction.
Convert all the digits of the literal at once, so that it rounds to
the nearest double: `100000000000000041 * 1` now gives
`100000000000000050` instead of `100000000000000030`.
Comparing numbers whose exponents are about 2^31 apart, such as
`1e999999999 > 1e-1147483646`, overflowed a signed int in decNumber.
Reserve one more digit when capping the decimal precision, so the
exponent gap stays within int while it is converted to units. The
smallest exponent moves from -1147483646 to -1147483645, so
`1e-1147483646` now prints as `0E-1147483645` instead of
`1E-1147483646`.
gmtime/0 and localtime/0 converted the number of seconds to time_t
before checking it, which is undefined behavior for nan, infinite and
values like 1e20 that do not fit, so jq built with UBSan aborted.
Check the range first and raise the existing "error converting number
of seconds since epoch to datetime" error, which strftime/1 and
strflocaltime/1 also report for such numbers. The error can now be
caught: `try (1e20 | gmtime) catch .` returns the message instead of
aborting, and an input of exactly 2^63 is rejected too.
On 32-bit platforms, builtin.c defined _TIME_BITS=64, but glibc
rejects it unless _FILE_OFFSET_BITS=64 is also defined. The configure
script passes that only where off_t is not already 64-bit, so the build
failed on x32. Define _FILE_OFFSET_BITS=64 too when it is not defined,
and respect a _TIME_BITS given by the build.
`break $label` is implemented as an error whose message is the label object, so the destructuring alternative operator (`?//`) caught it on backtracking and retried the next pattern instead of letting it reach its label. Detect break's control-flow error, unwrapping the wrapping added by `try`, and propagate it.
`isfinite` checked only for infinities, so `nan | isfinite` was true
and `finites` let NaN through. A finite number is neither infinite nor
NaN, as in C's `isfinite`, `Number.isFinite` and `math.isfinite`.
`current_line` was incremented only when a read contained a newline,
so `input_line_number` and error locations reported the previous line
for a value whose line had not been terminated yet: the last line of
input without a trailing newline, or a value ending exactly on the
read-buffer boundary.
Track whether the last read stopped short of a newline and add it to
the reported line number.
`f_match` converted each match and capture offset to a codepoint index
by walking from the start of the input, so `match(re; "g")`, `scan`
and `capture(re; "g")` were quadratic in the number of matches.
Count offsets from a cursor at the last converted position instead,
stepping back when a capture starts before it (lookbehind, `\K`).
Since #3633, `reduce` pushes a copy of its input before the `FORK`,
and that copy stays in a slot saved by the `FORK` until the loop ends.
When `init` holds `.`, as in `_assign` and `_modify`, the copy is a
second reference to the accumulator, so the first `setpath` in each
reduction copies the whole input. Building an object key by key with
`.[$k] = $v`, `|=` or `+=` became quadratic again, the slowdown #618
reported and `DUPN` was added to fix.
Store the input in a variable before the `FORK` and load it with
`LOADVN` at the start of the loop instead. The slots saved by the
`FORK` no longer refer to the input while the body runs, and the slot
below `init` is still not popped destructively, so #3227 stays fixed.
The Pipfile did not specify a Python version, so Dependabot locked
dependencies with its own default Python. This dropped packages needed
only on older Python (e.g. typing-extensions, required by referencing on
Python < 3.13) and broke the manpages job running on Python 3.11.
Pin python_version in the Pipfile and use the same version in CI so the
lockfile matches what CI installs, and relock the dependencies.
The mktime/0 function failed for 1969-12-31T23:59:59Z with "invalid
gmtime representation", because its result -1 is also the failure value
of timegm(), and for 1969-12-31T23:59:58Z with "mktime not supported on
this platform", because of a leftover check for -2.
Tell a failure apart from the valid result -1 by tm_wday, which is set
to -1 before the conversion and overwritten only on success, and remove
the check for -2. Now `-2, -1 | gmtime | mktime` round-trip to -2 and -1,
as do normalized inputs such as [1970,0,0,23,59,59,0,0], which gives -1.
Inputs that the platform rejects, such as years before 1900 on macOS,
still fail with "invalid gmtime representation".
The i386 build ran on ubuntu-22.04, which is retired on April 17, 2027,
and ubuntu-24.04 lacks fmod and exp10 in the static i386 libm.
Build on ubuntu-26.04 for every architecture except MIPS, whose cross
toolchains Ubuntu 26.04 no longer ships, and move the decnum, oniguruma
and valgrind workflows too. Most release binaries are now built with
GCC 15 and glibc 2.43, and they remain statically linked.
The static i386 libm of glibc 2.43 does not define drem, so linking jq
with --enable-all-static on Ubuntu 26.04 failed.
Call remainder for drem wherever it is available, as jq already did on
macOS. drem is an obsolete name for remainder, so the results do not
change, and jq no longer depends on the legacy symbol.
The macOS jobs failed during the macos-14 brownouts, and the image is
retired on November 2, 2026.
Run them on macos-15 and build with the macos14 target triple instead
of deriving it from uname -r, so the binaries still require macOS 14.0
as in jq 1.8.x rather than following the runner to 15. Recent clang
ignores the version in a darwinNN triple and uses the SDK default.
A multibyte UTF-8 sequence cut short by a non-continuation byte took
every remaining byte of the string, so "a\xf0Zb" became "a\ufffd".
Replace only the lead byte and the continuation bytes that follow it,
the same as an invalid sequence that is not cut short, so "a\xf0Zb"
now becomes "a\ufffdZb". This also changes length and explode on such
strings, which now count the characters that used to be dropped.
The NetBSD job failed when installing git on a fresh runner, because the
image ships pcre2-10.48 and the git package needs pcre2>=10.48nb1, and
pkg_add does not update installed dependencies by default.
Pass -uu to pkg_add so it also updates installed dependencies that are
too old. Also drop the PKG_PATH override. netbsd-vm now writes the live
package mirrors for the running release to /etc/pkg_install.conf, so the
override is no longer needed to avoid the image's 9.0 fallback.
A format without %d left the day of the month at 0, which mktime and
todate read as the last day of the previous month, and the weekday was
wrong for dates in January and February of 1900 and 2100.
Start parsing from the 1st, so a format without a day now gives the
first of the month, and a time-only format no longer outputs the 8 and
367 placeholders for the weekday and day of the year. This also fixes
the weekday of dates in January and February of 1900 and 2100.
Both were defined as explode | map(...) | implode, which took 4 seconds
on a 10 MB string, about 90 times as long as parsing it.
Change the case of A-Z or a-z a byte at a time in C, copying multibyte
UTF-8 sequences unchanged, so the output stays the same and the 10 MB
case now takes about 60 ms including parsing. On a non-string input the
error now names the function, "ascii_downcase input must be a string",
instead of "explode input must be a string".
The manual says halt_error prints its input with no decoration, not
even a newline, but non-string values such as {"a":"xyz"} were printed
with a trailing newline.
Dump non-string values to JSON and print them the same way as strings,
so {"a":"xyz"} | halt_error(1) now writes exactly {"a":"xyz"} to stderr.
The tutorial is where most people meet jq, but it was missing key
filters like select and abbreviated commands in ways that are hard for
beginners to follow.
Grow the page from 7 examples to 24, newly covering -r and -c, chained
paths and slicing, map, sort_by, group_by, select, test, to_entries,
from_entries, with_entries, string interpolation and @tsv. The sample
data is pinned with the API's until parameter and the outputs avoid
GitHub account data, so running the commands gives exactly the output
shown.
The manual's "Defining Functions" section shows only one-argument
functions, so it never says how to pass more than one. This adds a short
paragraph: arguments are separated by `;` in both `def f(a; b):` and
`f(.x; .y)`, and `f(.x, .y)` instead calls a one-argument `f` with the
filter `.x, .y`. It also adds an example for each. `tests/man.test` and
`jq.1.prebuilt` are regenerated.
Fixes#2163
The manual said `a op= b` is equivalent to `a |= . op b`. It is actually
equivalent to `(b as $b | a |= . op $b)`: the right-hand side gets `.`
as input, not the value being updated, and each value it outputs gives a
separate result.
This updates the description and adds two examples, `.a += .b` and `.a
+= (1,2)`. `tests/man.test` and `jq.1.prebuilt` are regenerated.
Fixes#2119, fixes#2407
Nothing tested that jq --run-tests exits with status 1 when the
tests fail, so a failure could have been reported as a pass.
Add shell tests with incorrect, missing and extra output that check
both the exit status and the reported message, such as "Insufficient
results", along with a passing control. Under Valgrind, memory errors
exit with status 99 so they are not mistaken for a test failure.
The manual recommended backslash-escaped double quotes inside the jq
program for all PowerShell versions, but since PowerShell 7.3 native
command arguments are passed with standard quoting by default, so the
backslashes reach jq literally.
Describe the quoting rules separately for Unix shells and PowerShell
7.3+, for older PowerShell and Windows PowerShell, and for cmd.exe, and
update the examples to match.
Since jq 1.8.0, negating a number literal computed 0 - x, so -0 and
0 | -. printed 0 while (0+0) | -. printed -0.
Flip the sign bit with decNumberCopyNegate() instead, so -0 prints -0
again as it did in jq 1.7, and -(-0) is still 0.
jvp_utf8_next() had a fast path for ASCII, but it is not inlined into
its callers, so every byte of a string cost a function call.
Move the end check and the ASCII case into a static inline function in
jv_unicode.h and keep the rest out of line. This speeds up parsing of
string-heavy input by up to 1.17x and string functions such as length,
explode and @html, with the same output for every input.
Enable colored output by default only when the TERM environment variable
is set to a value other than dumb, as git and grep do, so that users no
longer need to pass -M or set NO_COLOR on terminals that cannot display
escape sequences. Colored output is now disabled not only for TERM=dumb
but also when TERM is unset or empty. The -C option still enables colors
in all these cases. On Windows, colored output is still decided by
ANSICON and the console mode, and TERM is not checked.
These functions failed with "unknown system failure" whenever strftime()
returned 0 for a non-empty format, but 0 also means the format expands to
an empty string, as %p does in a locale without AM/PM.
Prepend a character to the format and trim it from the result, so that 0
can only mean the result is too long. Now 0 | strflocaltime("%p") gives
"" in fr_FR.UTF-8, and a result that is still too long fails with
"result too long" error instead. The size limit is unchanged.
In --seq mode, a parse error was reported as "need RS to resync", but
parsing continued in the middle of the broken text, so fragments of it
were reported as more errors or output as values.
Set the parser state to wait for the next RS after resetting the parser,
instead of before, so that the rest of the broken text is skipped as
RFC 7464 recommends.
Printing a string wrote each character with a separate call, one
fwrite() per character, or one jv_string_append_buf() for tojson and
tostring, which made output of string-heavy data slow.
Scan ahead for the next byte that needs escaping and write the run of
bytes before it with a single call, without changing the output.
Printing strings is now significantly faster, most of all for long
strings with few characters to escape, and the same applies to tojson
and tostring. With --ascii-output, text that is almost all non-ASCII is
about the same speed, since nearly every byte is escaped anyway.
A call passing more than 4095 arguments at the start of a nested
function body aborted jq after reporting the compile errors, with
"Assertion failed: (nemb > 0 && sz > 0), function jv_mem_calloc" and
exit status 134.
Stop compiling a function before its bytecode is allocated when it has
compile errors, since the bytecode is only generated and used when
compilation succeeds. jq now prints the same compile errors followed by
"jq: 2 compile errors" and exits with status 3, as it does for other
compile errors, instead of crashing.
halt_error with a negative exit code did not exit with that code. The
code collided with the internal status values for null or false output
and for no output, so halt_error(-1) exited with 0, or with 1 under
--exit-status.
Keep the low 8 bits of a negative code, as exit(3) does on POSIX
systems, so halt_error(-1) now exits with 255 and halt_error(-2) with
254, the same with or without --exit-status. Under --exit-status this
replaces the previous absolute value, so halt_error(-2) used to exit
with 2 and halt_error(-255) with 255, and they now exit with 254 and 1.
Converting a double outside the int range to int is undefined behavior,
and has() and del() did it on array indices like infinite or 1e10, which
UBSan reports as "inf is outside the range of representable values of
type 'int'". Only NaN was guarded against.
Clamp the index to the int range in has(), as getting and setting array
elements already do, and drop out-of-range indices in del() before they
are converted. Such indices can never refer to an element, so has()
returns false and del() leaves the array unchanged, the same as for
indices past the end of the array. Valid indices deleted together with
out-of-range ones, as in del(.[0, 1e10]), are still deleted.
Add a BSD workflow with FreeBSD and NetBSD jobs that run the same build
and tests as the linux job, each inside a VM booted under QEMU on an
ubuntu-latest runner. The tests/shtest $NO_COLOR pty checks are now
skipped on NetBSD, as they already are on SunOS.
The UTF-8 BOM was stripped only at the start of the parser stream, but jq
feeds all input files into a single parser, so a BOM at the start of the
second and later files reached the parser as content and failed with a
confusing "Invalid numeric literal" error. Strip it in the file readers
instead, at the start of each input file including stdin, and in
jv_load_file.
This also strips the BOM for raw input, so -R and --rawfile no longer
yield a leading U+FEFF, and a BOM at the start of a -f program file or an
imported module is now accepted rather than reported as a syntax error.
In exchange, "\uFEFF1" | fromjson is now a parse error, since a U+FEFF
inside a string is content rather than an encoding marker, and the
dedicated "Malformed BOM" error is gone.
The date in the .TH line of jq.1.prebuilt changed whenever the manual was
regenerated in a new month, causing merge conflicts between pull requests
that touch the manual, and it did not reflect the release date anyway.
Generate the committed man page without a date.
Stamp the date into jq.1 at build time instead, taking it from the current
commit, or from SOURCE_DATE_EPOCH where that is set, so that release
tarballs and distribution builds still carry one and the behaviour added
in #3514 is kept. Write it in UTC and in ISO 8601 rather than the previous
"%B %Y", for which mandoc reports "cannot parse date, using it verbatim".