Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Use $.getJSON() to send an HTTP GET request and handle the server’s JSON response as parsed JavaScript data. The example below sends a query parameter, reads a property from the response, and handles failure.

A simple jQuery.getJSON() example

Suppose the server returns JSON with this shape:

{ "name": "Ari" }

Request the endpoint and read the parsed name value like this:

$.getJSON("/api/user", { id: 42 })
  .done(function (data) {
    console.log(data.name);
  })
  .fail(function (jqXHR, textStatus, errorThrown) {
    console.error("Request failed:", textStatus, errorThrown);
  });

The URL and response shape are illustrative; replace them with an endpoint and JSON structure your server actually provides. The { id: 42 } object is encoded as query data and appended to the GET URL.

What the method expects

The signature is jQuery.getJSON(url [, data ] [, success ]). It loads JSON-encoded data with an HTTP GET request. Its optional data argument can contain values to send as URL query parameters, and the response is parsed before it reaches the success handler.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

For a success callback passed directly as the third argument, jQuery documents the arguments as (data, textStatus, jqXHR). The returned jqXHR also supports Promise-style handlers: .done() for success, .fail() for failure, and .always() for code that should run after either outcome. See the jQuery.getJSON() API documentation.

Handling errors and invalid JSON

The .fail() handler receives jqXHR, textStatus, and errorThrown. Depending on the failure, status values can include timeout, error, abort, or parsererror. A malformed JSON response can trigger a parsing failure: JSON requires double quotes around strings and property names, unlike JavaScript object literals. The jQuery.ajax() documentation describes the failure callback arguments and status values.

Independent reader supportYour contribution helps us test, update, and keep practical guides available for everyone.Support on Ko-Fi

When to use getJSON() instead of ajax()

$.getJSON() is a concise shortcut for $.ajax({ dataType: "json", url: url, data: data, success: success }). Use it when a GET request for JSON is all you need. Use $.ajax() when you need to set additional request options; both forms use jQuery Ajax behavior. The getJSON() reference documents the shorthand relationship.

Browser and version caveats

  • Cross-origin requests: Ordinary Ajax requests are subject to the browser’s same-origin policy. A request to another domain, subdomain, port, or protocol may fail unless the server and browser setup allow it.
  • JSONP: A URL containing a callback pattern such as callback=? is treated as JSONP by jQuery. JSONP and cross-domain GET requests do not use XHR, so jqXHR and textStatus may be undefined in callbacks. JSONP is a distinct request mode, not a general way to bypass browser security rules. Details are in the jQuery.getJSON() documentation.
  • Older callback methods: The jqXHR methods .success(), .error(), and .complete() were removed in jQuery 3.0. Use .done(), .fail(), and .always() instead; see jQuery.get() documentation.

Product prices and availability are accurate as of the date/time indicated and are subject to change. Any price and availability information displayed on Amazon at the time of purchase will apply.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.