How do I send a GET request to get JSON?

To get JSON from a REST API endpoint, you must send an HTTP GET request and pass the "Accept: application/json" request header to the server, which will tell the server that the client expects JSON in response. In this GET JSON example, we send a GET request to the ReqBin echo URL. Click Send to execute the GET JSON example online and see the results.
How do I send a GET request to get JSON? Send
GET /echo/get/json HTTP/1.1
Accept: application/json

Updated: Viewed: 10484 times

What is JSON?

JavaScript Object Notation is a text-based, language-independent format for storing and transmitting data over a network. JSON represents four primitive types (strings, numbers, boolean values, and null) and two structured types (objects and arrays). JSON file names use the .json file extension. JSON is used for client/server communication in mobile and web applications written in many programming languages, including JavaScript, Python, Java, C++, C#, Go, PHP, and many others.

What is HTTP GET?

The HTTP GET request method is used to request data-specified resources from the server. The HTTP GET method is one of nine standard HTTP (Hypertext Transfer Protocol) methods. HTTP GET requests should only receive data and do not change the server's state.

How to send a GET request to get JSON data?

The client indicates to the server a list of supported formats using the HTTP Accept header. For example, browsers send GET requests with the Accept header in the following format:

Accept Request-Header Syntax
Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,image/apng,*/*

The server selects the appropriate content type and informs the browser of its choice using the Content-type response header.

For the server to return a JSON response, the client must explicitly indicate that it expects to receive JSON data with the following header:

Accept Header Syntax
Accept: application/json

If the Accept header is not present in the request, the server assumes that the client accepts all media types.

GET request to get JSON data Example

Example of getting JSON data from ReqBin echo URL:

GET Request to Retrieve a JSON Example
GET /echo/get/json HTTP/1.1
Accept: application/json

You will receive a response from the server:

Response Example
HTTP/1.1 200 OK
Content-Type: application/json
Content-Length: 19

See also

Generate Code Snippets for GET Request Retrieve JSON Example

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