How do I return JSON in HTTP response?

To return JSON from the server, you must include the JSON data in the body of the HTTP response message and provide a "Content-Type: application/json" response header. The Content-Type response header allows the client to interpret the data in the response body correctly. In this JSON response example, we send a request to the ReqBin echo URL and provide the "Accept: application/json" request header to tell the server that the client is expecting JSON. In response to our request, the server sends us a JSON response and includes the "Content-Type: application/json" and Content-Length headers, which indicate the type and size of the data in the response body. Click Send to execute return JSON in the web HTTP response, and see the results.
Loading...