Currently, when I want to pretty-print a json file using jq, I use:
cat file.json | jq .
Yet I would expect for jq
to accept a file name as argument without having to fallback on cat
.
The man page says:
jq [options...] filter [files...]
... By default, jq reads a stream of JSON objects (whitespace separated) from stdin. One or more files may be specified, in which case jq will read input from those instead.
Yet running:
jq file.json
fails by throwing compile errors that the keys are not defined.
How am I supposed to add the file when running jq
?
jq . file.json | sponge file.json
(this requiressponge
frommoreutils
) – Flimm Jun 08 '22 at 18:29jq . file.json > file.json
? – Steve Anderson Oct 31 '22 at 18:43find . -type f -exec sh -c 'jq . "{}"|sponge "{}"' \;
– Joe Bane Oct 24 '23 at 16:00