How to put JSON data on the Server? [Curl/Bash Code]

To put JSON data to the server, you need to make an HTTP PUT request to the server and specify the correct MIME type for the JSON in the PUT request body. The correct MIME type for JSON is application/json. In this PUT JSON example, the Content-Type: application/json request header specifies the media type for JSON in the body of the HTTP PUT message, and the Accept: application/json request header tells the server that the client is expecting JSON in the server's response. In this PUT JSON to the Server example, we are making an HTTP PUT request to the ReqBin echo URL. The Curl/Bash code was automatically generated for the PUT JSON example.
How to put JSON data on the Server? [Curl/Bash Code] Send
PUT /echo/put/json HTTP/1.1
Host: reqbin.com
Accept: application/json
Content-Type: application/json
Content-Length: 81

{
  "Id": 78912,
  "Customer": "Jason Sweet",
  "Quantity": 1,
  "Price": 18.00
}
Updated: Viewed: 10792 times
Curl/Bash code for PUT JSON example

Curl/Bash code for PUT JSON Example

This Curl/Bash code snippet was generated automatically for the PUT JSON example.
<< Back to the PUT JSON example

What is JSON?

JSON (JavaScript Object Notation) is a language-independent format for storing and exchanging data. The JSON format is used with almost any programming language and API. JSON is widely used by web applications to exchange data between a web browser and a server and exchange data between servers via REST or JSON APIs. The JSON format is well suited for serializing complex and large data structures. JSON files can contain only text, not take up much disk space, and have a .json extension.

What is HTTP?

Hypertext Transfer Protocol (HTTP) is a network data transfer protocol that enables the communication between HTTP clients (browser or mobile application) and servers. HTTP is built on request-response messages between a client and a server. The client sends a request to the server, then the server processes this request and sends a response back to the client.

What is the HTTP PUT method used for?

The HTTP PUT request method is used to update an existing resource on the server. You can send any data in the body of the PUT request. Data type and size are not limited. The PUT request method is defined as idempotent, which means that multiple identical PUT requests should have the same effect as a single request (do not cause any changes in data).

To update an existing resource on the server, the client must provide a JSON that contains mutable fields with new values. If the requested object does not exist, the server can create it. In this case, the server informs the client that the resource has been created with a 201 (Created) status code in response to the PUT request. If the requested resource is successfully updated, the server will return 200 (OK) or 204 (No Сontent) status codes.

PUT JSON Example

An example of sending JSON data to ReqBin echo URL using the HTTP PUT method:

PUT JSON Request Example
PUT /echo/put/json HTTP/1.1
Host: reqbin.com
Accept: application/json
Content-Type: application/json
Content-Length: 81

{
  "Id": 78912,
  "Customer": "Jason Sweet",
  "Quantity": 1,
  "Price": 18.00
}

Server response to our PUT request:

Server Response to PUT Request
HTTP/1.1 200 OK
Content-Type: application/json
Content-Length: 19

{"success":"true"}

See also

Generate code snippets for Curl/Bash and other programming languages

Convert your PUT JSON request to the PHP, JavaScript/AJAX, Curl/Bash, Python, Java, C#/.NET code snippets using the Curl/Bash code generator.