What is JSON?
JSON (JavaScript Object Notation) is a text format for representing structured data based on the syntax of the JavaScript language. The .json extension is used to identify JSON files. There are many programming languages that use JSON to exchange data, including Python, Java, JavaScript, PHP, C++, C#, Go, and many more.
{
"Id": 78912,
"Customer": "Jason Sweet",
"Quantity": 1,
"Price": 18.00
} What is Content Type?
The Content-Type header indicates the type of media the resource uses in an HTTP entity. A content type is specified according to MIME (Multipurpose Email Extensions), which are standardized and published by the Internet Assigned Numbers Authority (IANA). The Content-Type header describes the nature of data in the body of HTTP messages by identifying type identifiers, subtype identifiers, and optional parameters.
Content-Type: image/png
Content-Type: text/html; charset=UTF-8
Content-Type: multipart/form-data; Why is it important to specify the correct content type for JSON?
Each resource transmitted over HTTP has a media type, also known as a MIME type, that describes the resource type and allows browsers and servers to understand it properly. As an example, if the server is capable of accepting both JSON and XML content types on one endpoint, a Content-Type of application/json will tell the server to interpret the body data as JSON, whereas a Content-Type of application/xml will tell the server to interpret the body data as XML.
Content-Type: application/json How to send JSON with correct Content-Type header?
The following is an example of posting JSON data to the ReqBin echo URL:
POST /echo/post/json HTTP/1.1
Host: reqbin.com
Content-Type: application/json
Content-Length: 81
{
"Id": 78912,
"Customer": "Jason Sweet",
"Quantity": 1,
"Price": 18.00
} How to get JSON with correct Content-Type header?
The following is an example of loading JSON data from the ReqBin echo URL:
HTTP/1.1 200 OK
Content-Type: application/json
Content-Length: 19
{"success":"true"} See also
Generate Code Snippets for JSON Content Type Example
Convert your JSON Content Type request to the PHP, JavaScript/AJAX, Node.js, Curl/Bash, Python, Java, C#/.NET code snippets using the ReqBin code generator.
