Let a coding agent search large JSON without reading it all
A coding agent that opens a large JSON file whole fills its context window with records it never needed. Have it run gronify search events.json error --count and then gronify search events.json error -m 5 instead: the first prints one number, and the second prints five path = value lines and stops reading the file.
Updated
Why an agent should not read a large JSON file whole
A context window is a fixed budget, and a file read spends it whether or not the content answers the question. Exports and API responses are usually minified, so the whole document is one line. The sample file on this page, events.json, is a gateway export of 4,000 request events:
wc -c events.json 899858 events.jsonwc -l events.json 1 events.jsonhead -n 20 events.json | wc -c 899858gronify --no-color flatten events.json | wc -l 44679gronify --no-color flatten events.json | wc -c 1806856That is 899,858 bytes on a single line, so head -n 20 prints the entire file and a read tool that pages by line number returns all of it. Flattening everything does not help: each line repeats its path, and the 44,679 lines come to 1,806,856 bytes, twice the source. The cap is what keeps output small.
Most of the file is also irrelevant to any one task. The question used below concerns 4 of the 4,000 events.
The narrowing loop: shape, count, sample, exact paths
Say the agent is asked which requests in that export failed with PAYMENT_PROVIDER_DOWN. Five steps answer it. Each prints a small, known amount and tells the agent what to ask next.
Shape first
flatten --limit 18 prints the first 18 path lines and stops. That shows the header object, the name of the array, and every field of one record.
gronify --no-color flatten --limit 18 events.jsonjson = {}json.export = {}json.export.source = "api-gateway"json.export.generated_at = "2026-11-10T06:00:00.000Z"json.export.window_hours = 24json.export.event_count = 4000json.events = []json.events[0] = {}json.events[0].id = "evt_000001"json.events[0].ts = "2026-11-09T06:00:00.313Z"json.events[0].service = "search"json.events[0].region = "ap-southeast-2"json.events[0].request = {}json.events[0].request.method = "GET"json.events[0].request.path = "/v1/search"json.events[0].request.trace_id = "b32ed95cc7f620548d05aa2110b500c5"json.events[0].status = 200json.events[0].duration_ms = 30Stopped after 18 lines (--limit); there may be moreThen volume
The first record succeeded, so the shape does not show where failures are recorded. --count prints one number, which tells the agent whether a term is safe to print.
gronify --no-color search events.json --count error672gronify --no-color search events.json --count PAYMENT_PROVIDER_DOWN4672 lines mention error, which is too many to print. The code from the question appears 4 times.
Then a sample
-m 4 prints the first four matches in document order. Here they are one complete error object, so the agent learns its fields without seeing the other 668 lines.
gronify --no-color search events.json -m 4 errorjson.events[33].error = {}json.events[33].error.code = "RATE_LIMITED"json.events[33].error.message = "too many requests for this API key"json.events[33].error.retryable = trueStopped after 4 matches (--max-count); there may be moreThen the exact paths
With a count of 4, the specific term can be printed in full, and each line carries the array index of a failing event. The guide to finding a JSON path goes deeper on this step.
gronify --no-color search events.json PAYMENT_PROVIDER_DOWNjson.events[611].error.code = "PAYMENT_PROVIDER_DOWN"json.events[1874].error.code = "PAYMENT_PROVIDER_DOWN"json.events[1875].error.code = "PAYMENT_PROVIDER_DOWN"json.events[3302].error.code = "PAYMENT_PROVIDER_DOWN"Then only the values
A regex on the path side reads three fields from those four records. Patterns are JavaScript regular expressions, and the guide on how to grep JSON explains the matching rules.
gronify --no-color search events.json --regex 'events\[(611|1874|1875|3302)\]\.(ts|region|duration_ms) 'json.events[611].ts = "2026-11-09T09:39:58.460Z"json.events[611].region = "eu-west-1"json.events[611].duration_ms = 10294json.events[1874].ts = "2026-11-09T17:14:39.152Z"json.events[1874].region = "us-east-1"json.events[1874].duration_ms = 10069json.events[1875].ts = "2026-11-09T17:15:00.071Z"json.events[1875].region = "eu-west-1"json.events[1875].duration_ms = 10094json.events[3302].ts = "2026-11-10T01:48:43.457Z"json.events[3302].region = "ap-southeast-2"json.events[3302].duration_ms = 10370The six commands above printed 42 lines, 1,630 bytes in total with the stderr notices included, from a file of 899,858 bytes.
What a cap does to the read
-m and --limit stop reading the input at the cap, so the cost of a capped command follows how far into the file its last line sits. The Stopped after notice goes to stderr, and stdout holds only path lines:
gronify --no-color search events.json -m 4 error 2>/dev/null | wc -l 4Input after the cap is never parsed, so it is never validated. On a copy of the export cut off at 450,000 bytes, the capped search exits 0 and the count, which has to read to the end, fails:
head -c 450000 events.json > truncated.jsongronify --no-color search truncated.json -m 2 error.code; echo $?json.events[33].error.code = "RATE_LIMITED"json.events[64].error.code = "VALIDATION_FAILED"Stopped after 2 matches (--max-count); there may be more0gronify --no-color search truncated.json --count error.code; echo $?Error: searching JSON: Unterminated string at byte offset 449976 (line 1, column 449977)1A capped result is a sample from a file the agent has not finished checking. The guide to searching large JSON files covers the streaming read on multi-gigabyte inputs.
Flags that keep output safe for a model to read
Plain text with --no-color
Gronify colors output only when stdin and stdout are both terminals and NO_COLOR is unset, so output captured through a pipe is already plain. Some agent harnesses run commands in a pseudo-terminal, and under one the line for json.events[611] began ^[[34mjson^[[39m^[[90m.^[[39m^[[36mevents^[[39m in cat -v. --no-color removes the escape codes in every case.
Stable order with --sort
Default output follows the key order of the document. --sort orders the keys of every object, so the same data always prints the same lines and two runs can be compared with the system diff:
cat a.json{"name":"api","port":8080,"flags":{"debug":false,"trace":true}}cat b.json{"flags":{"trace":true,"debug":false},"port":8080,"name":"api"}diff <(gronify --no-color flatten --sort a.json) <(gronify --no-color flatten --sort b.json) && echo samesameLeave --sort off exploratory commands when the root of the document is an object, as in the export above. Sorted output cannot start until that object closes, so a cap no longer ends the read early.
Branching with --exit-status
A yes-or-no question needs no output at all. With --exit-status, the exit code is 0 for a match, 1 for no match, and 2 for an error such as invalid JSON:
gronify --no-color search --exit-status events.json -m 1 PAYMENT_PROVIDER_DOWN > /dev/null 2>&1; echo $?0gronify --no-color search --exit-status events.json -m 1 DISK_FULL > /dev/null 2>&1; echo $?1gronify --no-color search --exit-status truncated.json DISK_FULL > /dev/null 2>&1; echo $?2Atomic files with -o
-o saves a result for a later step and replaces the file only after the run succeeds. Below, the second run fails partway through its input and the 56 lines from the first run stay in place:
gronify --no-color -o payment.gron search events.json --regex 'events\[(611|1874|1875|3302)\]\.'Output written to payment.gronwc -l payment.gron 56 payment.grongronify --no-color -o payment.gron search truncated.json --regex 'events\[(611|1874|1875|3302)\]\.'; echo $?Error: searching JSON (invalid regex or JSON): Unterminated string at byte offset 449976 (line 1, column 449977)1wc -l payment.gron 56 payment.gronInstall the Gronify agent skills
The repository ships six focused skills on skills.sh — led by gronify-json-flatten-search and large-json-search — that teach an agent this routine and its task-specific recipes. Install the suite or pick one skill with the open skills CLI:
npx skills add 1solomonwakhungu/gronifynpx skills add 1solomonwakhungu/gronify --skill gronify-json-flatten-searchThe CLI writes each skill under .agents/skills/<name>/SKILL.md and links it into detected agent directories such as .claude/skills/. Pass -a to choose agents (for example claude-code or cursor), -g to install at user level, or --list to preview every skill in the repository without installing:
gronify-json-flatten-search: complete Gronify workflow — check availability and version (1.2.0+ for caps/--sort/--exit-status, 1.4.0+ for--stream/--jsonl), pass--no-color, go from--countto-mtoflatten --limit, check exit codes, and round-trip withunflatten.large-json-search: strict size gate (wc -c), 5-step narrowing loop, and compressed stream pipes for files over 50 KB to multi-GB exports.jsonl-ndjson-log-search: streaming.jsonl/.ndjsonlog and transcript exploration with--jsonl/-s(Gronify 1.4.0+; falls back tojq -con 1.3.2 and older).json-compare-sorted-diff: key-order-independent JSON comparison usingflatten --sortwith systemdiffandgit difftextconv.openapi-lockfile-json-search: path-anchored search recipes for OpenAPI/Swagger specs,package-lock.json,kubectl -o json, and cloud JSON.json-path-to-jq-and-unflatten: translate Gronify paths tojqor JSONPath, preserve 64-bit numbers verbatim, and unflatten filtered subsets.
The skills do not install the CLI automatically. They tell the agent to run command -v gronify first and either use npx gronify or ask before installing from npm or Homebrew, as the install section shows.
Instructions to paste into CLAUDE.md or AGENTS.md
An agent without the skill can follow the same routine from its project instructions file: CLAUDE.md for Claude Code, AGENTS.md for Codex CLI and other agents that read it. Claude Code 2.1.277 and later also reads AGENTS.md when the project has no CLAUDE.md. These lines agree with the skill:
cat AGENTS.md## JSON files- Check the size before opening any .json file: wc -c <file>- Under 50 KB, read the file normally.- Over 50 KB, never cat it or open it with a file-read tool. Use gronify, always with --no-color.- Learn the shape first: gronify --no-color flatten --limit 50 <file>- Count before printing: gronify --no-color search <file> <term> --count- Print a capped sample: gronify --no-color search <file> <term> -m 20- Narrow with --regex on the path. Drop the cap only after --count shows the result is small.- "Stopped after" on stderr means more lines may exist. A non-zero exit means the output is incomplete.- If command -v gronify prints nothing, ask before running: npm install -g gronifyThe 50 KB threshold is a guess to start from. Lower it for a model with a small context window, and raise it if most JSON in the repository is small config.
When the agent should use something else
A small file should be read directly. A config of a few hundred bytes costs less to read than the commands that would explore it.
Once the shape is known and the task is a transformation or an aggregate, jq is the better tool. Gronify has no query language, so it cannot group, sum, or join. One jq program counts every error code in the export:
jq -r '.events[].error.code // empty' events.json | sort | uniq -c 40 NOT_FOUND 4 PAYMENT_PROVIDER_DOWN 50 RATE_LIMITED 43 UPSTREAM_TIMEOUT 31 VALIDATION_FAILEDFor JSON Lines (NDJSON) logs with one JSON value per line, pass -s, --stream, or --jsonl to gronify flatten or gronify search; records stream one at a time and work with --count and -m. When the agent needs whole matching JSON objects back or wants to search across a directory of many log files, jq or ripgrep is often more direct:
cat app.jsonl{"level":"info","msg":"started"}{"level":"error","msg":"db timeout"}{"level":"info","msg":"stopped"}gronify --no-color search --stream app.jsonl errorjson[1].level = "error"jq -c 'select(.level == "error")' app.jsonl{"level":"error","msg":"db timeout"}