How to minify JSON with jq


Minify JSON string with jq:

echo '{ "foo": "bar" }' | jq -r tostring

Save the minified JSON string:

echo '{ "foo": "bar" }' | jq -r tostring > minified.json


Minify JSON file with jq:

jq -r tostring file.json

Save the minified JSON file:

jq -r tostring file.json > minified.json

Please support this site and join our Discord!