Skip to main content

curl's --json flag

TIL that curl supports a --json flag to send and accept JSON responses since version 7.82.0, which means that the following requests,

sh
curl --data '{"name": "morpheus"}' \
--header "Content-Type: application/json" \
--header "Accept: application/json" \
--request POST https://example.com/api/users

curl -d '{"name": "morpheus"}' \
-H "Content-Type: application/json" \
-H "Accept: application/json" \
-X POST https://example.com/api/users

can be further shortened as follows:

sh
curl --json '{"name": "morpheus"}' \
-X POST https://example.com/api/users

Source: https://glaforge.dev/posts/2023/03/22/curl-s-json-flag/