Find the path to any key or value in a JSON file
To find where a key or value sits in a JSON file, flatten the file so that every value prints next to its full path, then filter those lines. gronify search account.json grace@example.com prints json.users[1].email = "grace@example.com", and the same path without the leading json is the jq filter .users[1].email.
Updated
Find every path where a key appears
The examples use a small account record saved as account.json. With Gronify installed, flatten prints it as one json.path = value line per value:
gronify flatten account.jsonjson = {}json.account = {}json.account.id = 48213json.account.email = "billing@example.com"json.account.notes = "Send invoices to the billing email on file"json.users = []json.users[0] = {}json.users[0].name = "Ada"json.users[0].email = "ada@example.com"json.users[0].active = truejson.users[0].manager = nulljson.users[1] = {}json.users[1].name = "Grace"json.users[1].email = "grace@example.com"json.users[1].active = falsejson.users[1].manager = "Ada"json.settings = {}json.settings.email_notifications = truejson.settings["display name"] = "Team Ops"json.settings["api.example.com"] = {}json.settings["api.example.com"].timeout = 30json.settings["api.example.com"].retries = 3A plain search compares the term with the whole line. Searching for email returns the three email keys, and also a notes value that mentions the word and the longer key email_notifications:
gronify search account.json emailjson.account.email = "billing@example.com"json.account.notes = "Send invoices to the billing email on file"json.users[0].email = "ada@example.com"json.users[1].email = "grace@example.com"json.settings.email_notifications = trueTo match the key alone, describe its position on the line. The last key of a path is always followed by = , and a key that needs no quoting always has a dot in front of it. The pattern \.email = requires both:
gronify search account.json --regex '\.email = 'json.account.email = "billing@example.com"json.users[0].email = "ada@example.com"json.users[1].email = "grace@example.com"A key that holds an object or an array has a line of its own, so \.settings = returns json.settings = {}. Search ignores case unless you pass -c, which means the pattern above would also match a key spelled Email. A string value can contain the text .email = too. If your data might, use ^[^=]*\.email = , which accepts the key only when no equals sign comes before it. The regex dialect and the other search flags are in the guide on how to grep nested JSON, and the line format is described in the guide on flattening JSON.
Find the path to a known value
Values print to the right of = the way JSON writes them: strings in double quotes, numbers as written, and true, false, and null bare. Keep the = in the search term so the match stays on the value side.
A string
Include the quotes so the term matches the whole string and not a longer one that contains it. Ada is the value of two different keys, and each line says which:
gronify search account.json '= "Ada"'json.users[0].name = "Ada"json.users[1].manager = "Ada"A number
Plain search is a substring match, so = 3 also finds 30. Switch to a regex and anchor the end of the line with $:
gronify search account.json '= 3'json.settings["api.example.com"].timeout = 30json.settings["api.example.com"].retries = 3gronify search account.json --regex ' = 3$'json.settings["api.example.com"].retries = 3true, false, and null
The three literals are never quoted, so the same anchor tells null apart from a string that contains the word:
gronify search account.json --regex ' = null$'json.users[0].manager = nullgronify search account.json --regex ' = (true|false)$'json.users[0].active = truejson.users[1].active = falsejson.settings.email_notifications = trueA value inside an array of objects
The array index is part of the path, so a match inside a list of records names the record it came from. This address belongs to the second user, at index 1:
gronify search account.json grace@example.comjson.users[1].email = "grace@example.com"Turn the printed path into a jq filter
Gronify writes paths with the dot and bracket notation that jq filters use. Delete the leading json and the rest is a filter that returns the value:
jq '.users[1].email' account.json"grace@example.com"A key that is not a plain identifier, because it contains a space, a dot, or a hyphen, or starts with a digit, prints in bracket-quote form: json.settings["display name"]. jq accepts that form as it stands, so the rule does not change. Do not expand a dotted key into .settings.api.example.com. jq reads that as four nested keys and returns null.
gronify search account.json --regex 'display name|timeout'json.settings["display name"] = "Team Ops"json.settings["api.example.com"].timeout = 30jq '.settings["display name"]' account.json"Team Ops"jq '.settings["api.example.com"].timeout' account.json30jq '.settings.api.example.com.timeout' account.jsonnullOne kind of key needs a rewrite. Gronify treats $ as an identifier character and prints a key such as $ref bare, but jq 1.8.2 stops on .$ref with a syntax error. Quote it in brackets:
echo '{"$ref":"#/defs/user"}' | gronify flattenjson = {}json.$ref = "#/defs/user"echo '{"$ref":"#/defs/user"}' | jq '.["$ref"]'"#/defs/user"| Gronify prints | jq filter | What changed |
|---|---|---|
json.users[1].email | .users[1].email | The leading json is removed |
json.settings["display name"] | .settings["display name"] | Only the leading json is removed |
json[1].id or json["first name"], where a bracket follows json directly | .[1].id or .["first name"] | A dot is added in front |
json.users[1].email, wanted for every user | .users[].email | The index is deleted |
json.$ref | .["$ref"] | The key is quoted in brackets |
With the filter in hand, jq can select records by a condition and reshape them, which a path search cannot do. The guide on using Gronify alongside jq covers where each tool fits.
Find paths with jq alone
On a machine that has jq and where you cannot install anything else, jq can report paths by itself. It prints a path as an array of keys and indexes. paths(scalars | true) lists the path of every leaf value. The shorter paths(scalars) that most answers quote leaves out every false and null, which in this file drops users[0].manager and users[1].active:
jq -c 'paths(scalars | true)' account.json | head -5["account","id"]["account","email"]["account","notes"]["users",0,"name"]["users",0,"email"]To find a key, keep the paths whose last element is the key name. To find a value, wrap a recursive descent in path(), or pass the test to paths(), which is shorter:
jq -c 'paths | select(.[-1] == "email")' account.json["account","email"]["users",0,"email"]["users",1,"email"]jq -c 'path(.. | select(. == "grace@example.com"))' account.json["users",1,"email"]jq -c 'paths(. == "Ada")' account.json["users",0,"name"]["users",1,"manager"]getpath takes one of those arrays and returns the value. For a filter you can paste into another command, join the array into bracket form, which jq accepts for every key:
jq 'getpath(["users",1,"email"])' account.json"grace@example.com"jq -r 'paths(. == 30) | map("[\(tojson)]") | "." + join("")' account.json.["settings"]["api.example.com"]["timeout"]jq '.["settings"]["api.example.com"]["timeout"]' account.json30These comparisons are exact: . == 30 does not match 300, and . == "Ada" does not match a longer string. For a partial, case-insensitive match on strings, jq -c 'paths(strings | test("ada"; "i"))' account.json also returns the path of ada@example.com.
Fix "leaf_paths/0 is not defined" in jq
Many older answers list leaf paths with leaf_paths. The jq 1.6 manual calls it an alias of paths(scalars) and marks it deprecated, and the jq 1.7 release removed it. On jq 1.8.2 the old command fails like this:
jq -c 'leaf_paths' account.jsonjq: error: leaf_paths/0 is not defined at <top-level>, line 1, column 1: leaf_paths ^^^^^^^^^^jq: 1 compile errorReplace leaf_paths with paths(scalars) and nothing else in the filter needs to change. Both skip false and null leaves, so use paths(scalars | true) if you need those too.
Large or private files
A browser-based JSON path finder works on a document that you paste or upload into a web page. That stops being practical when the file is too large for a text box, and it may not be permitted for a file that holds customer records or credentials.
A command-line tool reads the file where it already is. Gronify parses the input as a stream and does not load it whole, so memory does not grow with the number of records. When one path is all you need, -m 1 stops reading at the first match:
gronify search account.json -m 1 --regex '\.email = 'json.account.email = "billing@example.com"Stopped after 1 match (--max-count); there may be moreMeasured time and memory for large inputs are in the benchmarks. gron and fastgron print the same json.users[1].email paths, so if either is already installed, piping its output through grep finds the same paths (gron ends each line with ;, so a pattern anchored with $ needs ;$), and the jq conversion above applies unchanged. To browse a document by hand, a terminal viewer such as jless is the better fit.
Use this workflow with a coding agent
To teach Claude Code, Cursor, Codex, or another supported agent to anchor key and value searches and translate printed paths into jq or JSONPath, install the json-path-to-jq-and-unflatten skill (see JSON exploration for AI coding agents):
npx skills add 1solomonwakhungu/gronify --skill json-path-to-jq-and-unflatten