How to do an unpretty print on pretty JSON file in shell >> serial string JSON >> ES _bulk?

You can try the great jq tool for parsing JSON in the shell. To de-pretty print with jq, you can use either method below:

cat pretty-printed.json | jq -c .
jq -c . pretty-printed.json

the -c (or –compact-output) tells it to not pretty print (which is the default). The “.” tells it to return the JSON content “as is” unmodified other than the reformatting. It gets dumped back to stdout, so you can redirect output or pipe it to something else.

P.S. I was looking to address the same problem and came to this option.

Leave a Comment