Skip to content
Latchkey

curl --json: Post JSON Without Boilerplate

--json replaces three flags with one, but it needs a recent curl.

The --json shortcut bundles the body, Content-Type, and Accept headers for the common case of talking to a JSON API.

What it does

--json <data> is shorthand that does three things: sends the data as the request body, sets Content-Type: application/json, and sets Accept: application/json. It implies POST. Like -d, a leading @ reads from a file. It was added in curl 7.82.0, so older runner images will not have it.

Common usage

Terminal
curl --json '{"ref":"main"}' https://api.example.com/deploy
curl --json @body.json https://api.example.com/x
# equivalent without --json:
curl -H 'Content-Type: application/json' -H 'Accept: application/json' -d @body.json https://api.example.com/x

Flags

FlagWhat it does
--json <data>Body + Content-Type + Accept JSON; implies POST (7.82+)
--json @fileRead the JSON body from a file
-d / --dataManual body, form-encoded type by default
-HSet headers yourself when --json is unavailable

In CI

Check curl --version on your runner. If it is older than 7.82, --json fails and you should fall back to -H 'Content-Type: application/json' -d @file. To keep scripts portable across runner images, the explicit -H + -d form is the safer choice.

Common errors in CI

curl: option --json: is unknown means the runner curl predates 7.82. Use the -H + -d equivalent instead. A 415 Unsupported Media Type means the server did not get Content-Type: application/json, which --json sets for you.

Related guides

Run this faster and cheaper on Latchkey managed runners. Start free →