Download the PHP package wikimedia/zest-jq without Composer
On this page you can find all versions of the php package wikimedia/zest-jq. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Informations about the package zest-jq
ZestJQ
A PHP and TypeScript implementation of the jq
JSON query language. Provides both a library API and a zestjq
command-line tool. ZestJQ uses the same license as the original
jq code (MIT). We implement jq version 1.8.x (validated against
upstream test cases as of May 2026).
This is not a port of the original C codebase, but a reimplementation
using the manual and the extensive jq.test file as a guide.
Claude Sonnet 4.6 was used to speed portions of the implementation
but every line in this code was manually reviewed and I performed
extensive clean up and refactoring on Claude's output. (Claude
became confused and began to call me "the linter" because I was always
altering what it output.)
Claude was a big help porting the numerous built-in functions in the
jq standard library. The date-parsing and other related functions
imported from C would not be nearly as complete if I had to port these
entirely by hand. After the PHP implementation was substantially
complete, Claude was used to assist the mostly-mechanical transformation
from PHP to TypeScript, although again I reviewed every line and
made numerous refinements.
This implementation passes the upstream jq test suite (524 tests) with the following exceptions:
- JSON cannot represent NaN or infinity, and the PHP
json_decodeandjson_encodefunctions similarly refuse to emit or accept these values. Upstreamjquses an extended version of JSON to allow it to parse and emit these values; we do not. - Similarly, we use IEEE floating point, as implemented by PHP, to
represent all values and arithmetic. In some places upstream
jquses extended precision: exact int64 for integers and support for preserving input number literals exactly. The PHP implementation defines thejqbuilt-inshave_literal_numbersandhave_decnumtofalseto reflect our implementation choices. - We don't implement the module-level directives
module,include, andimport. - Our error message strings are consistent for most type checking
operations, and thus do not match upstream
jqexactly. - The
debugandinputbuilt-ins are not implemented, although there is skeleton support for providing different IO contexts to the evaluator. - We don't enforce JSON nesting and path depth limits, and our
recursive implementation may use more stack that upstream
jqfor some operations.
We've also fixed some bugs in delete-path support. Since PHP is a memory-safe language, we expect that we do not have any memory errors either.
Additional documentation can be found on mediawiki.org.
PHP installation
PHP ≥ 8.1 is required. ext-mbstring must be enabled.
PHP library usage
Evaluate a filter against a JSON string
Evaluate a filter against a decoded PHP value
Compile once, evaluate many times
Error handling
Custom definitions
Running PHP tests
Individual test commands:
TypeScript installation
TypeScript library usage (node)
Evaluate a filter against a JSON string
Evaluate a filter against a decoded value
Compile once, evaluate many times
Error handling
TypeScript library usage (browser)
Build the browser bundle from the project root:
This produces three files in dist/browser/:
zestjq.iife.js— unminified IIFE bundle (for debugging)zestjq.iife.min.js— minified IIFE bundle (recommended for production)zestjq.esm.js— ES module bundle (for use with<script type="module">)
Via <script> tag (IIFE)
The IIFE bundle exposes all exports as properties of window.ZestJQ:
Via ES module
Compile once, evaluate many times (browser)
Running TypeScript tests
Command-line tool
Our command-line tool is compatible with the upstream jq binary,
although we do not implement many command-line options.
| Option | Description |
|---|---|
-n, --null-input |
Use null as the input instead of reading stdin/files |
-r, --raw-output |
Print strings without JSON quoting |
-c, --compact-output |
Compact JSON output (no pretty-printing) |
--ast |
Print the parsed AST of the filter and exit |
Examples:
Cookbook
Common query patterns using a classic store inventory document.
Setup — replace $json / json with the JSON string above:
Get all authors:
Get the first book's title:
Every price field at any nesting depth:
Books cheaper than $10:
Books that have an ISBN:
First two books:
First and last book:
History
Upstream jq was created by Stephen Dolan and is currently maintained
by the jqlang community.
ZestJQ was originally implemented by C. Scott Ananian.
For version history since the original implementation, see HISTORY.md.
License and Credits
jq is copyright (C) 2012 Stephen Dolan and contributors.
ZestJQ is a clean reimplementation in PHP and does not incorporate
the original C source code, but it does include src/builtin.jq
and tests/jq.test from the upstream jq project.
The PHP implementation is copyright (C) 2026 Wikimedia Foundation.
Both the original jq codebase and this implementation are distributed under the MIT license; see LICENSE for details.