json-grep

Crates.iojson-grep
lib.rsjson-grep
version0.1.0
created_at2025-07-25 03:39:17.820278+00
updated_at2025-07-25 03:39:17.820278+00
descriptionA grep-like utility for searching JSON data with regular expressions
homepage
repositoryhttps://gitlab.com/cky/json-grep
max_upload_size
id1767154
size23,805
C. K. Young (cky)

documentation

README

json-grep

json-grep is a fairly minimal grep-style utility for searching JSON data for a given regular expression.

Features

  • Searches the unescaped input, unlike standard grep.
  • Prints out the path for each matched string (in JSONPath notation).

Limitations

  • Only Rust's regex syntax is supported. In particular, backreferences aren't supported.
  • Currently, the whole input is always read in, even if you want to stop after the first match.

Aims

The original intent is to identify where in the JSON input matches are found. I needed this because, having lost my sight in 2024, it had become impractical for me to use indentation to determine the tree location of the strings I was searching for—in particular, line-based locations like in standard grep are decidedly unuseful.

json-grep was also a way for me to learn serde's streaming API. Everything in json-grep is handled in a streaming way, allowing very large JSON input to be processed. (In theory—currently it loads the whole input into memory, but a future improvement seeks to use mmap for regular files and buffered reads for piped data.)

Non-aims

Despite paths being printed in JSONPath notation (since there's no point in reinventing a path notation), there are no plans to support JSONPath queries. This is because JSONPath queries require an actual JSON object tree to be built, and that's fundamentally opposite to the streaming approach: think of DOM vs SAX APIs but for JSON. I could theoretically support a subset of JSONPath queries that only handled name, index, and wildcard segments, without any support for extensions (or even negative indices for that matter), but then that wouldn't really be JSONPath, would it?

Commit count: 0

cargo fmt