How to minify JSON with jq


String

Minify JSON string with jq:

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

Save the minified JSON string:

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

File

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!