[{"content":" Blog post: jq recipes you\u0026rsquo;ll actually use Reference: jq manual\nProblem JSON from an API/CLI/config file needs reshaping — extract fields, filter elements, flatten to lines — without writing a script. jq\u0026rsquo;s filter language does it in one expression; these are the patterns that cover ~95% of daily use.\nBasics jq \u0026#39;.\u0026#39; # pretty-print jq \u0026#39;.field\u0026#39; # one field jq \u0026#39;.a.b.c\u0026#39; # nested field jq \u0026#39;.items[0]\u0026#39; # first array element jq \u0026#39;.items[-1]\u0026#39; # last element jq \u0026#39;.items[0:3]\u0026#39; # slice (first 3) jq \u0026#39;length\u0026#39; # array/object size jq \u0026#39;keys\u0026#39; # object keys Arrays jq \u0026#39;.[]\u0026#39; # every element (flatten) jq \u0026#39;.[].name\u0026#39; # one field from each jq \u0026#39;.[].name\u0026#39; -r # -r: raw output, no quotes jq \u0026#39;map(.name)\u0026#39; # same, but stays an array jq \u0026#39;map(.name) | sort\u0026#39; # sort the array jq \u0026#39;map(.name) | unique\u0026#39; # dedupe jq \u0026#39;first(.[] | select(.active))\u0026#39; # first match jq \u0026#39;contains([\u0026#34;a\u0026#34;,\u0026#34;b\u0026#34;])\u0026#39; # array includes all listed jq \u0026#39;.[] | select(.x \u0026gt; 5)\u0026#39; # filter elements jq \u0026#39;group_by(.env)\u0026#39; # group into arrays Objects jq \u0026#39;{name, id}\u0026#39; # build object from fields jq \u0026#39;.[] | {name, id}\u0026#39; # object per element jq \u0026#39;to_entries\u0026#39; # [{key, value}, ...] jq \u0026#39;to_entries[] | \u0026#34;\\(.key)=\\(.value)\u0026#34;\u0026#39; # flatten to key=value jq \u0026#39;with_entries(.key |= ascii_upcase)\u0026#39; # transform all keys jq \u0026#39;del(.secrets)\u0026#39; # remove fields jq \u0026#39;.a + .b\u0026#39; # merge objects Strings \u0026amp; interpolation jq \u0026#39;.[] | \u0026#34;\\(.org)/\\(.repo):\\(.version)\u0026#34;\u0026#39; # interpolation jq -r \u0026#39;.[] | join(\u0026#34;,\u0026#34;)\u0026#39; # join array fields jq \u0026#39;test(\u0026#34;regex\u0026#34;)\u0026#39; # boolean match jq \u0026#39;.[] | select(.name | test(\u0026#34;^harbour-\u0026#34;))\u0026#39; # filter by regex jq \u0026#39;ascii_downcase\u0026#39; # case ops jq \u0026#39;ltrimstr(\u0026#34;prefix\u0026#34;)\u0026#39; # strip prefix Conditionals \u0026amp; logic jq \u0026#39;if .env == \u0026#34;prod\u0026#34; then \u0026#34;p\u0026#34; else \u0026#34;np\u0026#34; end\u0026#39; jq \u0026#39;.[] | select(.env == \u0026#34;prod\u0026#34; and .enabled)\u0026#39; jq \u0026#39;.value // \u0026#34;default\u0026#34;\u0026#39; # fallback for null/missing jq \u0026#39;.items | any(.ready)\u0026#39; # any element true jq \u0026#39;.items | all(.ready)\u0026#39; # all elements true jq \u0026#39;.items | INDEX(.id)\u0026#39; # array → map keyed by .id Aggregation jq \u0026#39;[.[] | .size] | add\u0026#39; # sum jq \u0026#39;[.[] | .v] | min, max\u0026#39; # min/max jq \u0026#39;sort_by(.created) | last\u0026#39; # latest jq \u0026#39;map(select(.x)) | length\u0026#39; # count matches Handy combos jq -r \u0026#39;.[] | [.id, .name] | @tsv\u0026#39; # tab-separated rows jq -r \u0026#39;.[] | [.id, .name] | @csv\u0026#39; # CSV jq -r \u0026#39;paths | join(\u0026#34;.\u0026#34;)\u0026#39; # every leaf path jq \u0026#39;getpath([\u0026#34;a\u0026#34;,\u0026#34;b\u0026#34;])\u0026#39; # safe nested get jq \u0026#39;.. | objects | select(has(\u0026#34;token\u0026#34;))\u0026#39; # find anywhere in tree jq -S \u0026#39;.\u0026#39; # sort all keys (canonical diff) gh api patterns # one field per element gh api orgs/ORG/installations --jq \u0026#39;.installations[] | {app_id, app_slug}\u0026#39; # find a specific app gh api orgs/ORG/installations \\ --jq \u0026#39;.installations[] | select(.app_slug==\u0026#34;ifc-mentor-jenkins\u0026#34;) | {app_id, id}\u0026#39; # file list from a tree gh api repos/ORG/REPO/git/trees/main?recursive=1 --jq \u0026#39;.tree[].path\u0026#39; # repo names only gh api \u0026#39;orgs/ORG/repos?per_page=100\u0026#39; --jq \u0026#39;.[].name\u0026#39; # count gh api \u0026#39;orgs/ORG/repos?per_page=100\u0026#39; --jq \u0026#39;length\u0026#39; # raw file content (skip jq entirely) gh api repos/ORG/REPO/contents/path.yaml -H \u0026#34;Accept: application/vnd.github.raw\u0026#34; Gotchas .foo.bar fails on null parents → use .foo?.bar or .foo // {}. -r for scripts/config; keep JSON mode when piping to another jq. select() filters elements; map() transforms — mixing them up is the #1 mistake. @tsv/@csv need -r to look right. gh api --jq = gh api then pipe to jq; identical to gh api ... | jq .... ","permalink":"http://kb.shoujun.dev/kb/devops/jq-cheatsheet/","summary":"\u003cblockquote\u003e\n\u003cp\u003eBlog post: \u003ca href=\"https://blog.shoujun.dev/2026/11/jq-recipes-youll-actually-use.html\"\u003ejq recipes you\u0026rsquo;ll actually use\u003c/a\u003e\nReference: \u003ca href=\"https://jqlang.org/manual/\"\u003ejq manual\u003c/a\u003e\u003c/p\u003e\n\u003c/blockquote\u003e\n\u003ch2 id=\"problem\"\u003eProblem\u003c/h2\u003e\n\u003cp\u003eJSON from an API/CLI/config file needs reshaping — extract fields, filter\nelements, flatten to lines — without writing a script. jq\u0026rsquo;s filter\nlanguage does it in one expression; these are the patterns that cover ~95%\nof daily use.\u003c/p\u003e\n\u003ch2 id=\"basics\"\u003eBasics\u003c/h2\u003e\n\u003cdiv class=\"highlight\"\u003e\u003cpre tabindex=\"0\" style=\"color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;-webkit-text-size-adjust:none;\"\u003e\u003ccode class=\"language-bash\" data-lang=\"bash\"\u003e\u003cspan style=\"display:flex;\"\u003e\u003cspan\u003ejq \u003cspan style=\"color:#e6db74\"\u003e\u0026#39;.\u0026#39;\u003c/span\u003e                        \u003cspan style=\"color:#75715e\"\u003e# pretty-print\u003c/span\u003e\n\u003c/span\u003e\u003c/span\u003e\u003cspan style=\"display:flex;\"\u003e\u003cspan\u003ejq \u003cspan style=\"color:#e6db74\"\u003e\u0026#39;.field\u0026#39;\u003c/span\u003e                   \u003cspan style=\"color:#75715e\"\u003e# one field\u003c/span\u003e\n\u003c/span\u003e\u003c/span\u003e\u003cspan style=\"display:flex;\"\u003e\u003cspan\u003ejq \u003cspan style=\"color:#e6db74\"\u003e\u0026#39;.a.b.c\u0026#39;\u003c/span\u003e                   \u003cspan style=\"color:#75715e\"\u003e# nested field\u003c/span\u003e\n\u003c/span\u003e\u003c/span\u003e\u003cspan style=\"display:flex;\"\u003e\u003cspan\u003ejq \u003cspan style=\"color:#e6db74\"\u003e\u0026#39;.items[0]\u0026#39;\u003c/span\u003e                \u003cspan style=\"color:#75715e\"\u003e# first array element\u003c/span\u003e\n\u003c/span\u003e\u003c/span\u003e\u003cspan style=\"display:flex;\"\u003e\u003cspan\u003ejq \u003cspan style=\"color:#e6db74\"\u003e\u0026#39;.items[-1]\u0026#39;\u003c/span\u003e               \u003cspan style=\"color:#75715e\"\u003e# last element\u003c/span\u003e\n\u003c/span\u003e\u003c/span\u003e\u003cspan style=\"display:flex;\"\u003e\u003cspan\u003ejq \u003cspan style=\"color:#e6db74\"\u003e\u0026#39;.items[0:3]\u0026#39;\u003c/span\u003e              \u003cspan style=\"color:#75715e\"\u003e# slice (first 3)\u003c/span\u003e\n\u003c/span\u003e\u003c/span\u003e\u003cspan style=\"display:flex;\"\u003e\u003cspan\u003ejq \u003cspan style=\"color:#e6db74\"\u003e\u0026#39;length\u0026#39;\u003c/span\u003e                   \u003cspan style=\"color:#75715e\"\u003e# array/object size\u003c/span\u003e\n\u003c/span\u003e\u003c/span\u003e\u003cspan style=\"display:flex;\"\u003e\u003cspan\u003ejq \u003cspan style=\"color:#e6db74\"\u003e\u0026#39;keys\u0026#39;\u003c/span\u003e                     \u003cspan style=\"color:#75715e\"\u003e# object keys\u003c/span\u003e\n\u003c/span\u003e\u003c/span\u003e\u003c/code\u003e\u003c/pre\u003e\u003c/div\u003e\u003ch2 id=\"arrays\"\u003eArrays\u003c/h2\u003e\n\u003cdiv class=\"highlight\"\u003e\u003cpre tabindex=\"0\" style=\"color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;-webkit-text-size-adjust:none;\"\u003e\u003ccode class=\"language-bash\" data-lang=\"bash\"\u003e\u003cspan style=\"display:flex;\"\u003e\u003cspan\u003ejq \u003cspan style=\"color:#e6db74\"\u003e\u0026#39;.[]\u0026#39;\u003c/span\u003e                      \u003cspan style=\"color:#75715e\"\u003e# every element (flatten)\u003c/span\u003e\n\u003c/span\u003e\u003c/span\u003e\u003cspan style=\"display:flex;\"\u003e\u003cspan\u003ejq \u003cspan style=\"color:#e6db74\"\u003e\u0026#39;.[].name\u0026#39;\u003c/span\u003e                 \u003cspan style=\"color:#75715e\"\u003e# one field from each\u003c/span\u003e\n\u003c/span\u003e\u003c/span\u003e\u003cspan style=\"display:flex;\"\u003e\u003cspan\u003ejq \u003cspan style=\"color:#e6db74\"\u003e\u0026#39;.[].name\u0026#39;\u003c/span\u003e -r              \u003cspan style=\"color:#75715e\"\u003e# -r: raw output, no quotes\u003c/span\u003e\n\u003c/span\u003e\u003c/span\u003e\u003cspan style=\"display:flex;\"\u003e\u003cspan\u003ejq \u003cspan style=\"color:#e6db74\"\u003e\u0026#39;map(.name)\u0026#39;\u003c/span\u003e               \u003cspan style=\"color:#75715e\"\u003e# same, but stays an array\u003c/span\u003e\n\u003c/span\u003e\u003c/span\u003e\u003cspan style=\"display:flex;\"\u003e\u003cspan\u003ejq \u003cspan style=\"color:#e6db74\"\u003e\u0026#39;map(.name) | sort\u0026#39;\u003c/span\u003e        \u003cspan style=\"color:#75715e\"\u003e# sort the array\u003c/span\u003e\n\u003c/span\u003e\u003c/span\u003e\u003cspan style=\"display:flex;\"\u003e\u003cspan\u003ejq \u003cspan style=\"color:#e6db74\"\u003e\u0026#39;map(.name) | unique\u0026#39;\u003c/span\u003e      \u003cspan style=\"color:#75715e\"\u003e# dedupe\u003c/span\u003e\n\u003c/span\u003e\u003c/span\u003e\u003cspan style=\"display:flex;\"\u003e\u003cspan\u003ejq \u003cspan style=\"color:#e6db74\"\u003e\u0026#39;first(.[] | select(.active))\u0026#39;\u003c/span\u003e  \u003cspan style=\"color:#75715e\"\u003e# first match\u003c/span\u003e\n\u003c/span\u003e\u003c/span\u003e\u003cspan style=\"display:flex;\"\u003e\u003cspan\u003ejq \u003cspan style=\"color:#e6db74\"\u003e\u0026#39;contains([\u0026#34;a\u0026#34;,\u0026#34;b\u0026#34;])\u0026#39;\u003c/span\u003e      \u003cspan style=\"color:#75715e\"\u003e# array includes all listed\u003c/span\u003e\n\u003c/span\u003e\u003c/span\u003e\u003cspan style=\"display:flex;\"\u003e\u003cspan\u003ejq \u003cspan style=\"color:#e6db74\"\u003e\u0026#39;.[] | select(.x \u0026gt; 5)\u0026#39;\u003c/span\u003e     \u003cspan style=\"color:#75715e\"\u003e# filter elements\u003c/span\u003e\n\u003c/span\u003e\u003c/span\u003e\u003cspan style=\"display:flex;\"\u003e\u003cspan\u003ejq \u003cspan style=\"color:#e6db74\"\u003e\u0026#39;group_by(.env)\u0026#39;\u003c/span\u003e           \u003cspan style=\"color:#75715e\"\u003e# group into arrays\u003c/span\u003e\n\u003c/span\u003e\u003c/span\u003e\u003c/code\u003e\u003c/pre\u003e\u003c/div\u003e\u003ch2 id=\"objects\"\u003eObjects\u003c/h2\u003e\n\u003cdiv class=\"highlight\"\u003e\u003cpre tabindex=\"0\" style=\"color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;-webkit-text-size-adjust:none;\"\u003e\u003ccode class=\"language-bash\" data-lang=\"bash\"\u003e\u003cspan style=\"display:flex;\"\u003e\u003cspan\u003ejq \u003cspan style=\"color:#e6db74\"\u003e\u0026#39;{name, id}\u0026#39;\u003c/span\u003e                        \u003cspan style=\"color:#75715e\"\u003e# build object from fields\u003c/span\u003e\n\u003c/span\u003e\u003c/span\u003e\u003cspan style=\"display:flex;\"\u003e\u003cspan\u003ejq \u003cspan style=\"color:#e6db74\"\u003e\u0026#39;.[] | {name, id}\u0026#39;\u003c/span\u003e                  \u003cspan style=\"color:#75715e\"\u003e# object per element\u003c/span\u003e\n\u003c/span\u003e\u003c/span\u003e\u003cspan style=\"display:flex;\"\u003e\u003cspan\u003ejq \u003cspan style=\"color:#e6db74\"\u003e\u0026#39;to_entries\u0026#39;\u003c/span\u003e                        \u003cspan style=\"color:#75715e\"\u003e# [{key, value}, ...]\u003c/span\u003e\n\u003c/span\u003e\u003c/span\u003e\u003cspan style=\"display:flex;\"\u003e\u003cspan\u003ejq \u003cspan style=\"color:#e6db74\"\u003e\u0026#39;to_entries[] | \u0026#34;\\(.key)=\\(.value)\u0026#34;\u0026#39;\u003c/span\u003e  \u003cspan style=\"color:#75715e\"\u003e# flatten to key=value\u003c/span\u003e\n\u003c/span\u003e\u003c/span\u003e\u003cspan style=\"display:flex;\"\u003e\u003cspan\u003ejq \u003cspan style=\"color:#e6db74\"\u003e\u0026#39;with_entries(.key |= ascii_upcase)\u0026#39;\u003c/span\u003e  \u003cspan style=\"color:#75715e\"\u003e# transform all keys\u003c/span\u003e\n\u003c/span\u003e\u003c/span\u003e\u003cspan style=\"display:flex;\"\u003e\u003cspan\u003ejq \u003cspan style=\"color:#e6db74\"\u003e\u0026#39;del(.secrets)\u0026#39;\u003c/span\u003e                     \u003cspan style=\"color:#75715e\"\u003e# remove fields\u003c/span\u003e\n\u003c/span\u003e\u003c/span\u003e\u003cspan style=\"display:flex;\"\u003e\u003cspan\u003ejq \u003cspan style=\"color:#e6db74\"\u003e\u0026#39;.a + .b\u0026#39;\u003c/span\u003e                           \u003cspan style=\"color:#75715e\"\u003e# merge objects\u003c/span\u003e\n\u003c/span\u003e\u003c/span\u003e\u003c/code\u003e\u003c/pre\u003e\u003c/div\u003e\u003ch2 id=\"strings--interpolation\"\u003eStrings \u0026amp; interpolation\u003c/h2\u003e\n\u003cdiv class=\"highlight\"\u003e\u003cpre tabindex=\"0\" style=\"color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;-webkit-text-size-adjust:none;\"\u003e\u003ccode class=\"language-bash\" data-lang=\"bash\"\u003e\u003cspan style=\"display:flex;\"\u003e\u003cspan\u003ejq \u003cspan style=\"color:#e6db74\"\u003e\u0026#39;.[] | \u0026#34;\\(.org)/\\(.repo):\\(.version)\u0026#34;\u0026#39;\u003c/span\u003e   \u003cspan style=\"color:#75715e\"\u003e# interpolation\u003c/span\u003e\n\u003c/span\u003e\u003c/span\u003e\u003cspan style=\"display:flex;\"\u003e\u003cspan\u003ejq -r \u003cspan style=\"color:#e6db74\"\u003e\u0026#39;.[] | join(\u0026#34;,\u0026#34;)\u0026#39;\u003c/span\u003e                      \u003cspan style=\"color:#75715e\"\u003e# join array fields\u003c/span\u003e\n\u003c/span\u003e\u003c/span\u003e\u003cspan style=\"display:flex;\"\u003e\u003cspan\u003ejq \u003cspan style=\"color:#e6db74\"\u003e\u0026#39;test(\u0026#34;regex\u0026#34;)\u0026#39;\u003c/span\u003e                           \u003cspan style=\"color:#75715e\"\u003e# boolean match\u003c/span\u003e\n\u003c/span\u003e\u003c/span\u003e\u003cspan style=\"display:flex;\"\u003e\u003cspan\u003ejq \u003cspan style=\"color:#e6db74\"\u003e\u0026#39;.[] | select(.name | test(\u0026#34;^harbour-\u0026#34;))\u0026#39;\u003c/span\u003e \u003cspan style=\"color:#75715e\"\u003e# filter by regex\u003c/span\u003e\n\u003c/span\u003e\u003c/span\u003e\u003cspan style=\"display:flex;\"\u003e\u003cspan\u003ejq \u003cspan style=\"color:#e6db74\"\u003e\u0026#39;ascii_downcase\u0026#39;\u003c/span\u003e                          \u003cspan style=\"color:#75715e\"\u003e# case ops\u003c/span\u003e\n\u003c/span\u003e\u003c/span\u003e\u003cspan style=\"display:flex;\"\u003e\u003cspan\u003ejq \u003cspan style=\"color:#e6db74\"\u003e\u0026#39;ltrimstr(\u0026#34;prefix\u0026#34;)\u0026#39;\u003c/span\u003e                      \u003cspan style=\"color:#75715e\"\u003e# strip prefix\u003c/span\u003e\n\u003c/span\u003e\u003c/span\u003e\u003c/code\u003e\u003c/pre\u003e\u003c/div\u003e\u003ch2 id=\"conditionals--logic\"\u003eConditionals \u0026amp; logic\u003c/h2\u003e\n\u003cdiv class=\"highlight\"\u003e\u003cpre tabindex=\"0\" style=\"color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;-webkit-text-size-adjust:none;\"\u003e\u003ccode class=\"language-bash\" data-lang=\"bash\"\u003e\u003cspan style=\"display:flex;\"\u003e\u003cspan\u003ejq \u003cspan style=\"color:#e6db74\"\u003e\u0026#39;if .env == \u0026#34;prod\u0026#34; then \u0026#34;p\u0026#34; else \u0026#34;np\u0026#34; end\u0026#39;\u003c/span\u003e\n\u003c/span\u003e\u003c/span\u003e\u003cspan style=\"display:flex;\"\u003e\u003cspan\u003ejq \u003cspan style=\"color:#e6db74\"\u003e\u0026#39;.[] | select(.env == \u0026#34;prod\u0026#34; and .enabled)\u0026#39;\u003c/span\u003e\n\u003c/span\u003e\u003c/span\u003e\u003cspan style=\"display:flex;\"\u003e\u003cspan\u003ejq \u003cspan style=\"color:#e6db74\"\u003e\u0026#39;.value // \u0026#34;default\u0026#34;\u0026#39;\u003c/span\u003e                \u003cspan style=\"color:#75715e\"\u003e# fallback for null/missing\u003c/span\u003e\n\u003c/span\u003e\u003c/span\u003e\u003cspan style=\"display:flex;\"\u003e\u003cspan\u003ejq \u003cspan style=\"color:#e6db74\"\u003e\u0026#39;.items | any(.ready)\u0026#39;\u003c/span\u003e               \u003cspan style=\"color:#75715e\"\u003e# any element true\u003c/span\u003e\n\u003c/span\u003e\u003c/span\u003e\u003cspan style=\"display:flex;\"\u003e\u003cspan\u003ejq \u003cspan style=\"color:#e6db74\"\u003e\u0026#39;.items | all(.ready)\u0026#39;\u003c/span\u003e               \u003cspan style=\"color:#75715e\"\u003e# all elements true\u003c/span\u003e\n\u003c/span\u003e\u003c/span\u003e\u003cspan style=\"display:flex;\"\u003e\u003cspan\u003ejq \u003cspan style=\"color:#e6db74\"\u003e\u0026#39;.items | INDEX(.id)\u0026#39;\u003c/span\u003e                \u003cspan style=\"color:#75715e\"\u003e# array → map keyed by .id\u003c/span\u003e\n\u003c/span\u003e\u003c/span\u003e\u003c/code\u003e\u003c/pre\u003e\u003c/div\u003e\u003ch2 id=\"aggregation\"\u003eAggregation\u003c/h2\u003e\n\u003cdiv class=\"highlight\"\u003e\u003cpre tabindex=\"0\" style=\"color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;-webkit-text-size-adjust:none;\"\u003e\u003ccode class=\"language-bash\" data-lang=\"bash\"\u003e\u003cspan style=\"display:flex;\"\u003e\u003cspan\u003ejq \u003cspan style=\"color:#e6db74\"\u003e\u0026#39;[.[] | .size] | add\u0026#39;\u003c/span\u003e                \u003cspan style=\"color:#75715e\"\u003e# sum\u003c/span\u003e\n\u003c/span\u003e\u003c/span\u003e\u003cspan style=\"display:flex;\"\u003e\u003cspan\u003ejq \u003cspan style=\"color:#e6db74\"\u003e\u0026#39;[.[] | .v] | min, max\u0026#39;\u003c/span\u003e              \u003cspan style=\"color:#75715e\"\u003e# min/max\u003c/span\u003e\n\u003c/span\u003e\u003c/span\u003e\u003cspan style=\"display:flex;\"\u003e\u003cspan\u003ejq \u003cspan style=\"color:#e6db74\"\u003e\u0026#39;sort_by(.created) | last\u0026#39;\u003c/span\u003e           \u003cspan style=\"color:#75715e\"\u003e# latest\u003c/span\u003e\n\u003c/span\u003e\u003c/span\u003e\u003cspan style=\"display:flex;\"\u003e\u003cspan\u003ejq \u003cspan style=\"color:#e6db74\"\u003e\u0026#39;map(select(.x)) | length\u0026#39;\u003c/span\u003e           \u003cspan style=\"color:#75715e\"\u003e# count matches\u003c/span\u003e\n\u003c/span\u003e\u003c/span\u003e\u003c/code\u003e\u003c/pre\u003e\u003c/div\u003e\u003ch2 id=\"handy-combos\"\u003eHandy combos\u003c/h2\u003e\n\u003cdiv class=\"highlight\"\u003e\u003cpre tabindex=\"0\" style=\"color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;-webkit-text-size-adjust:none;\"\u003e\u003ccode class=\"language-bash\" data-lang=\"bash\"\u003e\u003cspan style=\"display:flex;\"\u003e\u003cspan\u003ejq -r \u003cspan style=\"color:#e6db74\"\u003e\u0026#39;.[] | [.id, .name] | @tsv\u0026#39;\u003c/span\u003e       \u003cspan style=\"color:#75715e\"\u003e# tab-separated rows\u003c/span\u003e\n\u003c/span\u003e\u003c/span\u003e\u003cspan style=\"display:flex;\"\u003e\u003cspan\u003ejq -r \u003cspan style=\"color:#e6db74\"\u003e\u0026#39;.[] | [.id, .name] | @csv\u0026#39;\u003c/span\u003e       \u003cspan style=\"color:#75715e\"\u003e# CSV\u003c/span\u003e\n\u003c/span\u003e\u003c/span\u003e\u003cspan style=\"display:flex;\"\u003e\u003cspan\u003ejq -r \u003cspan style=\"color:#e6db74\"\u003e\u0026#39;paths | join(\u0026#34;.\u0026#34;)\u0026#39;\u003c/span\u003e               \u003cspan style=\"color:#75715e\"\u003e# every leaf path\u003c/span\u003e\n\u003c/span\u003e\u003c/span\u003e\u003cspan style=\"display:flex;\"\u003e\u003cspan\u003ejq \u003cspan style=\"color:#e6db74\"\u003e\u0026#39;getpath([\u0026#34;a\u0026#34;,\u0026#34;b\u0026#34;])\u0026#39;\u003c/span\u003e                 \u003cspan style=\"color:#75715e\"\u003e# safe nested get\u003c/span\u003e\n\u003c/span\u003e\u003c/span\u003e\u003cspan style=\"display:flex;\"\u003e\u003cspan\u003ejq \u003cspan style=\"color:#e6db74\"\u003e\u0026#39;.. | objects | select(has(\u0026#34;token\u0026#34;))\u0026#39;\u003c/span\u003e  \u003cspan style=\"color:#75715e\"\u003e# find anywhere in tree\u003c/span\u003e\n\u003c/span\u003e\u003c/span\u003e\u003cspan style=\"display:flex;\"\u003e\u003cspan\u003ejq -S \u003cspan style=\"color:#e6db74\"\u003e\u0026#39;.\u0026#39;\u003c/span\u003e                               \u003cspan style=\"color:#75715e\"\u003e# sort all keys (canonical diff)\u003c/span\u003e\n\u003c/span\u003e\u003c/span\u003e\u003c/code\u003e\u003c/pre\u003e\u003c/div\u003e\u003ch2 id=\"gh-api-patterns\"\u003egh api patterns\u003c/h2\u003e\n\u003cdiv class=\"highlight\"\u003e\u003cpre tabindex=\"0\" style=\"color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;-webkit-text-size-adjust:none;\"\u003e\u003ccode class=\"language-bash\" data-lang=\"bash\"\u003e\u003cspan style=\"display:flex;\"\u003e\u003cspan\u003e\u003cspan style=\"color:#75715e\"\u003e# one field per element\u003c/span\u003e\n\u003c/span\u003e\u003c/span\u003e\u003cspan style=\"display:flex;\"\u003e\u003cspan\u003egh api orgs/ORG/installations --jq \u003cspan style=\"color:#e6db74\"\u003e\u0026#39;.installations[] | {app_id, app_slug}\u0026#39;\u003c/span\u003e\n\u003c/span\u003e\u003c/span\u003e\u003cspan style=\"display:flex;\"\u003e\u003cspan\u003e\n\u003c/span\u003e\u003c/span\u003e\u003cspan style=\"display:flex;\"\u003e\u003cspan\u003e\u003cspan style=\"color:#75715e\"\u003e# find a specific app\u003c/span\u003e\n\u003c/span\u003e\u003c/span\u003e\u003cspan style=\"display:flex;\"\u003e\u003cspan\u003egh api orgs/ORG/installations \u003cspan style=\"color:#ae81ff\"\u003e\\\n\u003c/span\u003e\u003c/span\u003e\u003c/span\u003e\u003cspan style=\"display:flex;\"\u003e\u003cspan\u003e  --jq \u003cspan style=\"color:#e6db74\"\u003e\u0026#39;.installations[] | select(.app_slug==\u0026#34;ifc-mentor-jenkins\u0026#34;) | {app_id, id}\u0026#39;\u003c/span\u003e\n\u003c/span\u003e\u003c/span\u003e\u003cspan style=\"display:flex;\"\u003e\u003cspan\u003e\n\u003c/span\u003e\u003c/span\u003e\u003cspan style=\"display:flex;\"\u003e\u003cspan\u003e\u003cspan style=\"color:#75715e\"\u003e# file list from a tree\u003c/span\u003e\n\u003c/span\u003e\u003c/span\u003e\u003cspan style=\"display:flex;\"\u003e\u003cspan\u003egh api repos/ORG/REPO/git/trees/main?recursive\u003cspan style=\"color:#f92672\"\u003e=\u003c/span\u003e\u003cspan style=\"color:#ae81ff\"\u003e1\u003c/span\u003e --jq \u003cspan style=\"color:#e6db74\"\u003e\u0026#39;.tree[].path\u0026#39;\u003c/span\u003e\n\u003c/span\u003e\u003c/span\u003e\u003cspan style=\"display:flex;\"\u003e\u003cspan\u003e\n\u003c/span\u003e\u003c/span\u003e\u003cspan style=\"display:flex;\"\u003e\u003cspan\u003e\u003cspan style=\"color:#75715e\"\u003e# repo names only\u003c/span\u003e\n\u003c/span\u003e\u003c/span\u003e\u003cspan style=\"display:flex;\"\u003e\u003cspan\u003egh api \u003cspan style=\"color:#e6db74\"\u003e\u0026#39;orgs/ORG/repos?per_page=100\u0026#39;\u003c/span\u003e --jq \u003cspan style=\"color:#e6db74\"\u003e\u0026#39;.[].name\u0026#39;\u003c/span\u003e\n\u003c/span\u003e\u003c/span\u003e\u003cspan style=\"display:flex;\"\u003e\u003cspan\u003e\n\u003c/span\u003e\u003c/span\u003e\u003cspan style=\"display:flex;\"\u003e\u003cspan\u003e\u003cspan style=\"color:#75715e\"\u003e# count\u003c/span\u003e\n\u003c/span\u003e\u003c/span\u003e\u003cspan style=\"display:flex;\"\u003e\u003cspan\u003egh api \u003cspan style=\"color:#e6db74\"\u003e\u0026#39;orgs/ORG/repos?per_page=100\u0026#39;\u003c/span\u003e --jq \u003cspan style=\"color:#e6db74\"\u003e\u0026#39;length\u0026#39;\u003c/span\u003e\n\u003c/span\u003e\u003c/span\u003e\u003cspan style=\"display:flex;\"\u003e\u003cspan\u003e\n\u003c/span\u003e\u003c/span\u003e\u003cspan style=\"display:flex;\"\u003e\u003cspan\u003e\u003cspan style=\"color:#75715e\"\u003e# raw file content (skip jq entirely)\u003c/span\u003e\n\u003c/span\u003e\u003c/span\u003e\u003cspan style=\"display:flex;\"\u003e\u003cspan\u003egh api repos/ORG/REPO/contents/path.yaml -H \u003cspan style=\"color:#e6db74\"\u003e\u0026#34;Accept: application/vnd.github.raw\u0026#34;\u003c/span\u003e\n\u003c/span\u003e\u003c/span\u003e\u003c/code\u003e\u003c/pre\u003e\u003c/div\u003e\u003ch2 id=\"gotchas\"\u003eGotchas\u003c/h2\u003e\n\u003cul\u003e\n\u003cli\u003e\u003ccode\u003e.foo.bar\u003c/code\u003e fails on null parents → use \u003ccode\u003e.foo?.bar\u003c/code\u003e or \u003ccode\u003e.foo // {}\u003c/code\u003e.\u003c/li\u003e\n\u003cli\u003e\u003ccode\u003e-r\u003c/code\u003e for scripts/config; keep JSON mode when piping to another jq.\u003c/li\u003e\n\u003cli\u003e\u003ccode\u003eselect()\u003c/code\u003e filters elements; \u003ccode\u003emap()\u003c/code\u003e transforms — mixing them up is the #1 mistake.\u003c/li\u003e\n\u003cli\u003e\u003ccode\u003e@tsv\u003c/code\u003e/\u003ccode\u003e@csv\u003c/code\u003e need \u003ccode\u003e-r\u003c/code\u003e to look right.\u003c/li\u003e\n\u003cli\u003e\u003ccode\u003egh api --jq\u003c/code\u003e = \u003ccode\u003egh api\u003c/code\u003e then pipe to jq; identical to \u003ccode\u003egh api ... | jq ...\u003c/code\u003e.\u003c/li\u003e\n\u003c/ul\u003e","title":"jq quick reference — the recipes you actually use"},{"content":" Blog post: Markdown to Word without the template tax\nProblem You need a .docx (Word) version of markdown content — runbooks, notes, tracking docs — without hand-maintaining a template or a placeholder contract. Pandoc output often needs post-editing; corporate recipients just want a Word file.\nSolution Use the agent skill simple-md-docx-converter — repo: https://gitlab.com/shoujunni/skill-md-docx-converter. It converts any well-formed .md to native Word constructs with python-docx:\nHeadings, paragraphs, lists (incl. task lists), tables, code fences, blockquotes, strikethrough, horizontal rules \u0026lt;mark\u0026gt; highlighting, inline images, {{toc}} fields, page breaks, multi-file merge Mermaid diagrams render to images via mmdc/Kroki/npx when available, else degrade to labelled text Optional --template (.docx/.dotx/.dotm or a named template from templates/) inherits corporate styles/headers/footers and fills {{key}} tokens via --set key=value Quick start git clone https://gitlab.com/shoujunni/skill-md-docx-converter.git cd skill-md-docx-converter # One-time: create the venv with python-docx ./scripts/setup.sh # Convert (writes input.docx next to input.md) .venv/bin/python scripts/convert_md_to_docx.py input.md # Merge several files, branded output .venv/bin/python scripts/convert_md_to_docx.py a.md b.md -o merged.docx \\ --template corporate-report --set title=\u0026#34;Quarterly Report\u0026#34; Useful flags: --code-theme \u0026lt;pygments-name\u0026gt;, --code-font \u0026lt;name\u0026gt;, --toc, --scan-placeholders, --open (open on completion), --no-verify.\nGotchas Run setup.sh first — it bootstraps pip and creates .venv; use --dev to also get pytest/pygments, --code-theme for highlighting. The pipeline strips YAML frontmatter, so Hugo/Jekyll posts convert cleanly. TOC fields are marked w:dirty — Word prompts to update fields on open; that is expected. Verify output with scripts/verify_docx_placeholders.py out.docx — confirms no unresolved {{tokens}} and sane file size (≥ 20 KB). ","permalink":"http://kb.shoujun.dev/kb/skills/markdown-to-docx-skill/","summary":"\u003cblockquote\u003e\n\u003cp\u003eBlog post: \u003ca href=\"https://blog.shoujun.dev/2026/11/markdown-to-word-without-template-tax.html\"\u003eMarkdown to Word without the template tax\u003c/a\u003e\u003c/p\u003e\n\u003c/blockquote\u003e\n\u003ch2 id=\"problem\"\u003eProblem\u003c/h2\u003e\n\u003cp\u003eYou need a \u003ccode\u003e.docx\u003c/code\u003e (Word) version of markdown content — runbooks, notes,\ntracking docs — without hand-maintaining a template or a placeholder\ncontract. Pandoc output often needs post-editing; corporate recipients\njust want a Word file.\u003c/p\u003e\n\u003ch2 id=\"solution\"\u003eSolution\u003c/h2\u003e\n\u003cp\u003eUse the agent skill \u003cstrong\u003esimple-md-docx-converter\u003c/strong\u003e —\nrepo: \u003ca href=\"https://gitlab.com/shoujunni/skill-md-docx-converter\"\u003ehttps://gitlab.com/shoujunni/skill-md-docx-converter\u003c/a\u003e.\nIt converts any well-formed \u003ccode\u003e.md\u003c/code\u003e to native Word constructs with\n\u003ccode\u003epython-docx\u003c/code\u003e:\u003c/p\u003e\n\u003cul\u003e\n\u003cli\u003eHeadings, paragraphs, lists (incl. task lists), tables, code fences,\nblockquotes, strikethrough, horizontal rules\u003c/li\u003e\n\u003cli\u003e\u003ccode\u003e\u0026lt;mark\u0026gt;\u003c/code\u003e highlighting, inline images, \u003ccode\u003e{{toc}}\u003c/code\u003e fields, page breaks,\nmulti-file merge\u003c/li\u003e\n\u003cli\u003eMermaid diagrams render to images via \u003ccode\u003emmdc\u003c/code\u003e/Kroki/\u003ccode\u003enpx\u003c/code\u003e when\navailable, else degrade to labelled text\u003c/li\u003e\n\u003cli\u003eOptional \u003ccode\u003e--template\u003c/code\u003e (.docx/.dotx/.dotm or a named template from\n\u003ccode\u003etemplates/\u003c/code\u003e) inherits corporate styles/headers/footers and fills\n\u003ccode\u003e{{key}}\u003c/code\u003e tokens via \u003ccode\u003e--set key=value\u003c/code\u003e\u003c/li\u003e\n\u003c/ul\u003e\n\u003ch2 id=\"quick-start\"\u003eQuick start\u003c/h2\u003e\n\u003cdiv class=\"highlight\"\u003e\u003cpre tabindex=\"0\" style=\"color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;-webkit-text-size-adjust:none;\"\u003e\u003ccode class=\"language-bash\" data-lang=\"bash\"\u003e\u003cspan style=\"display:flex;\"\u003e\u003cspan\u003egit clone https://gitlab.com/shoujunni/skill-md-docx-converter.git\n\u003c/span\u003e\u003c/span\u003e\u003cspan style=\"display:flex;\"\u003e\u003cspan\u003ecd skill-md-docx-converter\n\u003c/span\u003e\u003c/span\u003e\u003cspan style=\"display:flex;\"\u003e\u003cspan\u003e\n\u003c/span\u003e\u003c/span\u003e\u003cspan style=\"display:flex;\"\u003e\u003cspan\u003e\u003cspan style=\"color:#75715e\"\u003e# One-time: create the venv with python-docx\u003c/span\u003e\n\u003c/span\u003e\u003c/span\u003e\u003cspan style=\"display:flex;\"\u003e\u003cspan\u003e./scripts/setup.sh\n\u003c/span\u003e\u003c/span\u003e\u003cspan style=\"display:flex;\"\u003e\u003cspan\u003e\n\u003c/span\u003e\u003c/span\u003e\u003cspan style=\"display:flex;\"\u003e\u003cspan\u003e\u003cspan style=\"color:#75715e\"\u003e# Convert (writes input.docx next to input.md)\u003c/span\u003e\n\u003c/span\u003e\u003c/span\u003e\u003cspan style=\"display:flex;\"\u003e\u003cspan\u003e.venv/bin/python scripts/convert_md_to_docx.py input.md\n\u003c/span\u003e\u003c/span\u003e\u003cspan style=\"display:flex;\"\u003e\u003cspan\u003e\n\u003c/span\u003e\u003c/span\u003e\u003cspan style=\"display:flex;\"\u003e\u003cspan\u003e\u003cspan style=\"color:#75715e\"\u003e# Merge several files, branded output\u003c/span\u003e\n\u003c/span\u003e\u003c/span\u003e\u003cspan style=\"display:flex;\"\u003e\u003cspan\u003e.venv/bin/python scripts/convert_md_to_docx.py a.md b.md -o merged.docx \u003cspan style=\"color:#ae81ff\"\u003e\\\n\u003c/span\u003e\u003c/span\u003e\u003c/span\u003e\u003cspan style=\"display:flex;\"\u003e\u003cspan\u003e  --template corporate-report --set title\u003cspan style=\"color:#f92672\"\u003e=\u003c/span\u003e\u003cspan style=\"color:#e6db74\"\u003e\u0026#34;Quarterly Report\u0026#34;\u003c/span\u003e\n\u003c/span\u003e\u003c/span\u003e\u003c/code\u003e\u003c/pre\u003e\u003c/div\u003e\u003cp\u003eUseful flags: \u003ccode\u003e--code-theme \u0026lt;pygments-name\u0026gt;\u003c/code\u003e, \u003ccode\u003e--code-font \u0026lt;name\u0026gt;\u003c/code\u003e,\n\u003ccode\u003e--toc\u003c/code\u003e, \u003ccode\u003e--scan-placeholders\u003c/code\u003e, \u003ccode\u003e--open\u003c/code\u003e (open on completion),\n\u003ccode\u003e--no-verify\u003c/code\u003e.\u003c/p\u003e","title":"How to convert Markdown to Word (.docx) without templates"}]