Why Minify JSON for Production APIs?
While pretty-printed JSON is ideal during development for readability, sending indented JSON over the wire increases HTTP payload size, consumes extra network bandwidth, and elevates cloud egress costs at scale.
Minifying JSON removes extraneous spaces, tabs, and newlines without modifying data values, resulting in smaller transfer sizes and faster parsing times in mobile and IoT applications.
Minifying JSON on the Command Line with jq
# Minify a JSON file using jq:
jq -c . input.json > output.min.json
# Send minified payload via curl:
curl -X POST https://api.example.com/data \
-H "Content-Type: application/json" \
-d '$(cat output.min.json)'