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

is what I was looking for. I didn't realize that the . is a filter and not a placeholder for the piped in content:


The absolute simplest (and least interesting) filter is .. This is a filter that takes its input and produces it unchanged as output.

And the man page makes it clear that the filter is a required argument.

  • I was wrapping it - '.' Once I removed the quote marks it pretty printed. – barakbd Jul 21 '20 at 0:23
  • 5
    This command also works well with piping: <cmd_producing_json_to_std_out> | jq . – Thorkil Værge Aug 3 '20 at 14:33

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.