Home  >  Article  >  The author of cURL revealed: cURL will natively support JSON!

The author of cURL revealed: cURL will natively support JSON!

藏色散人
藏色散人forward
2022-01-23 09:35:202516browse

cURL author Daniel Stenberg revealed plans to add native support for JSON to cURL in an email.

The author of cURL revealed: cURL will natively support JSON!

Daniel explained the rationale for adding native support for JSON to cURL:

  • In areas such as REST APIs , sending JSON is very common

  • When many people are asked about considerations for choosing a cURL alternative, "ease of using JSON" is a common one

  • On sites like Stack Overflow, quite a few people are unable to send correct JSON and quote JSON correctly using cURL because JSON uses double quotes and the Shell does not expand variables within single quotes

Daniel also said that since he does not often send JSON, it is not appropriate to rely entirely on him to design this function. He needs help from others to make this feature as useful as possible.

Currently Daniel has provided a draft about this feature in the wiki and created a discussion forum.

In short, Daniel plans to add two command line options:

  • Send formatted JSON as a shortcut to -d with the matching Accept header

  • Send by constructing JSON request body

--json -||@filename
curl --json [whatever] http: //example.com

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

--jp [part]

('jp' is the abbreviation of "JSON part")

Build the JSON request body, and then use request headerContent-Type: application/json to send JSON.

[part] are instructions for building JSON content.

(Syntax inspired by jo)

View details: https://github.com/curl/curl/wiki/JSON

Statement:
This article is reproduced at:oschina.net. If there is any infringement, please contact admin@php.cn delete