A fast, jq-compatible command-line JSON processor built on simdjson.
sjq '.statuses[] | {id, name: .user.name}' twitter.json
sjq reads the jq language: the filters you
write for jq work with sjq, and on large inputs they run ten to forty times
faster on one thread, and up to 240 times faster with -P (several threads)
on large newline-delimited files. Documentation: https://simdjson.github.io/sjq/
Linux and macOS:
curl -fsSL https://raw.githubusercontent.com/simdjson/sjq/main/install.sh | sh
Windows (PowerShell):
irm https://raw.githubusercontent.com/simdjson/sjq/main/install.ps1 | iex
With a package manager:
brew install simdjson/tap/sjq # Homebrew (macOS, Linux)
scoop bucket add sjq https://github.com/simdjson/sjq # Scoop (Windows)
scoop install sjq/sjq
The scripts download the binary for your system from the latest release and check its SHA-256 checksum. The Linux binaries are static (x86-64 and ARM64), the macOS binary is universal, and Windows has x64 and ARM64 builds. One binary per system is enough: simdjson picks the fastest code for the processor at run time.
From source (CMake 3.15+, a C++17 compiler; CMake downloads simdjson 5.3.0,
or uses an installed one with -D SJQ_SYSTEM_SIMDJSON=ON):
cmake -B build
cmake --build build
ctest --test-dir build --output-on-failure
cmake --install build
- Command Prompt (cmd): single quotes are not quotes. Use double quotes, with
\"inside:sjq "select(.name == \"x\")" file.json. - Windows PowerShell 5 strips the double quotes inside arguments:
'."année"'reaches sjq as.année. - In both, put the filter in a file:
sjq -f filter.jq file.json. - PowerShell 5's
>writes UTF-16: usesjq -o out.json ...instead, and sjq writes UTF-8 itself. sjq reads UTF-16 files with a byte order mark.
Filters that only navigate and select (.a.b, select(...), {id, name})
run on simdjson's On-Demand API, which parses only what the filter reads: the
parts of a document they skip are not fully checked (sjq .a prints 1 for
{"a": 1, "b": tru}). Invalid UTF-8, unclosed strings and unbalanced
brackets are caught everywhere. --no-od checks every document in full, as
jq does.
sjq against jq 1.8.2 on 1 GB of NDJSON and on one 840 MB document (mean wall time, outputs identical; "sjq" runs on one thread, the default, and "sjq -P" on up to 32 threads; the documentation has the method and the table).
sjq implements the jq 1.8 language:
- paths,
select,map,reduce,foreachanddef - string interpolation and the
@csv,@tsvand@base64formats - assignment (
=,|=,+=, ...),deland path functions - destructuring, regular expressions and dates
input/inputs, and most options, including--arg,--argjson,-sand-R.
sjq also writes JSON in the compact yet readable
FracturedJson layout
(--fractured).
728 of the 781 tests of jq's own test suite pass, and the jq tutorial runs unchanged. The differences are listed in the documentation.
-
Tests:
ctest --test-dir buildruns:- golden cases recorded from jq 1.8.2 (
tests/cases); - targeted tests of memory mapping, pipes, parallel runs and errors;
- jq's own test suite;
- with a
jqin thePATH, a comparison of jq's and sjq's outputs.
See
tests/run_tests.py. - golden cases recorded from jq 1.8.2 (
-
Fuzzing:
-D SJQ_FUZZING=ONwith clang buildsfuzz_sjq(libFuzzer). -
Benchmarks:
bench/. -
Design notes:
doc/design.md. -
Releases: push a tag such as
v0.1.0; the release workflow builds and publishes the binaries andSHA256SUMS. If GitHub had no macOS runner, the release goes out without the macOS binary: runscripts/release-macos.sh v0.1.0on a Mac to build and attach it. The package managers follow the latest release once it is complete (all five binaries): thePackagesworkflow updates the Scoop manifest (bucket/sjq.json) and keeps the winget manifests as an artifact, and simdjson/homebrew-tap updates its formula. Both run after each release workflow and every six hours;scripts/update_packages.sh(called byrelease-macos.sh) runs them right away.
sjq was first developed in the simdjson repository (simdjson/simdjson#3143).
Apache 2.0 or MIT, at your option, as simdjson. The files under tests/jq
come from jq (MIT, see tests/jq/COPYING).