JSON requests

Inline body

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

Sends a JSON request body. -H sets the content type and -d sends the body; see curl.

Body from a file

curl -X POST https://api.example.com/items \
  -H 'Content-Type: application/json' \
  -d @item.json

Sends a JSON body from a file. @file keeps shell quoting out of the way. See curl.

JSON shortcut

curl --json '{"name":"Ada"}' \
  https://api.example.com/items

Sends JSON with one flag. --json sets the headers and POST method; see curl.

0 Comments for this cheatsheet. Write yours!