cURL author Daniel Stenberg emailed revealed about plans to add native support for JSON to cURL.

curl

Daniel explains the reasons for adding native JSON support to cURL:

  1. sending JSON is a common practice in areas such as REST APIs
  2. “Ease of use with JSON” was a common consideration when many people were asked about choosing a cURL alternative
  3. on sites like Stack Overflow, a significant number of people were unable to send the correct JSON and quote JSON correctly using cURL because JSON uses double quotes and the Shell does not expand variables inside single quotes

Daniel also said that since he doesn’t send JSON very often, it wasn’t appropriate to rely entirely on him to design this feature. He needs help from others to make this feature as useful as possible.

Currently Daniel has made a draft about this feature available in the wiki, and also created a discussion forum.

In brief, Daniel plans to add two command line options.

  1. send a formatted JSON as a shortcut to -d, with a matching Accept header
  2. send by constructing a JSON request body

--json -|<data>|@filename

1
curl --json [whatever] http://example.com

The above command line is a shortcut that is equivalent to -d [whatever] -H "Content-Type: application/json" .

--jp [part]

(‘jp’ is short for “JSON part”)

Construct the JSON request body and then send the JSON using the request header Content-Type: application/json.

[part] is the command to build the JSON content.

(Syntax inspired by jo)

See more: https://github.com/curl/curl/wiki/JSON