Skip to content

Processing JSON

Vladislav Zavialov edited this page Dec 6, 2026 · 1 revision

The examples below process the file saved by the Download JSON button with jq. The results shown are for the query ^type\b\s+\w+\s+::\s (standalone kind signatures).

Package names

jq -r '.packages[].name' hackage-search.json
AspectAG-0.8.0.0
MicroHs-0.17.4.0
Win32-notify-0.3.0.3
abstractly-keyed-implicits-0.1.1.0
...

Package names without versions

jq -r '.packages[].name | sub("-[0-9.]+$"; "")' hackage-search.json
AspectAG
MicroHs
Win32-notify
abstractly-keyed-implicits
...

Packages with the most matches

jq -r '.packages | sort_by(-.matches)[] | "\(.matches)\t\(.name)"' hackage-search.json
558	proarrow-0.4.0.0
253	moonlight-homology-0.1.0.3
209	moonlight-category-1.1.0.1
201	rel8-internal-1.8.0.0
...

Files with matches

jq -r '.packages[] | .name as $p | .files[] | "\($p)/\(.path)"' hackage-search.json
AspectAG-0.8.0.0/src/Language/AspectAG/RunningExample.lhs
AspectAG-0.8.0.0/src/Language/AspectAG.hs
MicroHs-0.17.4.0/lib/Control/Monad/Fix.hs-boot
MicroHs-0.17.4.0/lib/Data/Coerce.hs
...

Matching lines in grep style

jq -r '.packages[] | .name as $p | .files[] | .path as $f | .lines[]
       | select(any(.parts[]; has("match")))
       | "\($p)/\($f):\(.number): \([.parts[] | .context // .match] | join("") | sub("\r?\n$"; ""))"' hackage-search.json
AspectAG-0.8.0.0/src/Language/AspectAG/RunningExample.lhs:384: type H :: Grammar
AspectAG-0.8.0.0/src/Language/AspectAG/RunningExample.lhs:509: type G :: Grammar
AspectAG-0.8.0.0/src/Language/AspectAG.hs:878: type Sem :: Grammar
MicroHs-0.17.4.0/lib/Control/Monad/Fix.hs-boot:5: type MonadFix :: (Type -> Type) -> Constraint
...

Most frequent matches

jq -r '.. | .match? // empty' hackage-search.json | sort | uniq -c | sort -rn
     11 type Env :: 
     10 type T :: 
     10 type PickType :: 
     10 type Add :: 
...

Totals

jq '{query, packages: (.packages | length), files: ([.packages[].files[]] | length), matches}' hackage-search.json
{
  "query": "^type\\b\\s+\\w+\\s+::\\s",
  "packages": 271,
  "files": 1500,
  "matches": 4871
}

Clone this wiki locally