Node.js code for GET JSON ExampleThis Node.js code snippet was generated automatically for the GET JSON example.
<< Back to the GET JSON example
What it JSON?
How to request data in JSON format using Node.js?
To get data in JSON format from the server, the Node.js client must explicitly tell the server that it expects JSON by sending the Accept: application/json request header. Without the Accept header, the server may automatically send data in a different format that it thinks is best for the API client (based on the UserAgent header), and it might not be JSON.
Node.js JSON Request Example
An example of an HTTP GET request to fetch JSON data from a ReqBin echo URL. Click Generate Code to see the Node.js code for this JSON request example.
The server response to our Node.js client's request.
The server returned JSON in the body of the HTTP response message. The Content-Length: 19 header indicates the length of the JSON data in the response body, and the Content-Type: application/json response header indicates the type of data.
JSON MIME Type
The official MIME type for JSON is application/json: