on the site https://jqplay.org
w/o def walk(f): . as $in | if type == "object" then reduce keys[] as $key ( {}; . + { ($key): ($in[$key] | walk(f)) } ) | f elif type == "array" then map( walk(f) ) | f else f end;
throws error
jq: error: walk/1 is not defined
I actually have the same problem locally:
$ yaml2json api/api.yml | jq 'walk(.)'
jq: error: walk/1 is not defined at <top-level>, line 1:
walk(.)
jq: 1 compile error
events.js:72
throw er; // Unhandled 'error' event
^
Error: write EPIPE
at errnoException (net.js:901:11)
at Object.afterWrite (net.js:718:19)
$ jq --version
jq-1.5
the walk examples in the docs all seem to be broken too!
As stated on the jq FAQ page:
If your jq has walk/1 as a builtin, then it can be used as described below; otherwise, you can simply include its definition (available e.g. from https://github.com/stedolan/jq/blob/master/src/builtin.jq) in your jq script.
@pkoppstein ah, thanks for the heads up