jQuery getJSON() Method

Beginner
7 min read
Updated: Oct 2026
5 examples
Live preview

What Is getJSON()?

jQuery.getJSON(url [, data] [, success]) (since 1.0) is a GET shorthand for loading JSON. It is equivalent to $.ajax({ dataType: "json", url, data, success }). The success callback receives a parsed object or array — no manual JSON.parse().

Remember
$.getJSON(url, data, success)
// ≈
$.ajax({
  dataType: "json",
  url: url,
  data: data,
  success: success
});

// Returns jqXHR → chain .done() / .fail() / .always()
NeedUse
JSON GET (clearest)$.getJSON(url, data, fn)
GET any dataType$.get(url, data, fn, dataType)
POST JSON / full control$.ajax({ ... })
Load & run a script$.getScript(url)
Error path.fail(fn) on the returned jqXHR

How to Use getJSON()

Pass a URL, optional query data, then handle the parsed result.

  1. Call $.getJSON(url) with an optional data object and/or success callback.
  2. jQuery sends a GET; data becomes a query string.
  3. On success, the callback receives a parsed object or array.
  4. Chain .fail() (and optionally .always()) so errors are not silent.
  5. For JSONP, put callback=? in the URL when the API requires it.
PieceRequired?Role
urlYesEndpoint that returns JSON (or JSONP)
dataOptionalObject or string → appended as query params
successOptionalfunction(data, textStatus, jqXHR)
Return value—jqXHR Promise (.done / .fail / .always)

Pseudocode

Pseudocode
call $.getJSON(url, data?, success?)

build GET request with dataType = "json"
if data is an object:
    append url-encoded query string to url

send request asynchronously

if response is valid JSON:
    parse body → object or array
    call success(data, textStatus, jqXHR)
    resolve jqXHR → .done() handlers
else (HTTP error or bad JSON):
    reject jqXHR → .fail() handlers
    (bad JSON often silent unless .fail() is chained)

always → .always() handlers

Cheat Sheet

Keep these facts handy while loading JSON with jQuery.

TopicDetail
Syntax$.getJSON( url [, data ] [, success ] )
ReturnsjqXHR (Promise)
SincejQuery 1.0 · Promise chaining 1.5+
Equivalent$.ajax({ dataType: "json", url, data, success })
Success argsdata (parsed), textStatus, jqXHR
JSONPURL contains callback=?
Bad JSONUsually silent since 1.4 — chain .fail()
Prefer.done() / .fail() / .always() (not removed 3.0 APIs)

Live Preview

Run a real $.getJSON() against a public API and inspect the parsed result.

Live demo uses JSONPlaceholder. Needs network access.

Result
Ready — pick an action and click Run.

jQuery Examples

Short, copy-ready snippets. Open DevTools Console, or use Try It Yourself for a live editor.

Example 1 — Basic $.getJSON()

Fetch a user and show name and email when the request succeeds.

jQuery
$("#load").on("click", function () {
  $.getJSON(
    "https://jsonplaceholder.typicode.com/users/1",
    function (user) {
      $("#result").text(user.name + " · " + user.email);
      console.log(typeof user); // "object"
    }
  );
});
Try It Yourself

How It Works

  1. Click. The handler calls $.getJSON() with a URL and success fn.
  2. GET. jQuery requests JSON with dataType: "json".
  3. Parse. The body becomes a JavaScript object automatically.
  4. Use. Read user.name / user.email — no JSON.parse().

Example 2 — Official Pattern: $.each() List

Loop JSON fields with $.each() and append an unordered list — same idea as the jQuery docs.

jQuery
$.getJSON(
  "https://jsonplaceholder.typicode.com/users/1",
  function (user) {
    var items = [];
    var fields = {
      name: user.name,
      username: user.username,
      email: user.email,
      phone: user.phone,
      website: user.website
    };

    $.each(fields, function (key, val) {
      items.push("
  • " + key + ": " + val + "
  • "); }); $("
      ", { "class": "user-field-list", html: items.join("") }).appendTo("#list-container"); } );
    Try It Yourself

    How It Works

    1. Load. Success receives the full user object.
    2. Flatten. Pick string fields into a simple key/value map.
    3. Loop. $.each() pushes one <li> per field.
    4. Append. Create a <ul> and attach it to the page.

    Example 3 — Query Parameters via data

    Pass a plain object — jQuery appends it to the URL as a query string.

    jQuery
    $("#search").on("click", function () {
      var userId = $("#user-id").val() || 1;
    
      $.getJSON(
        "https://jsonplaceholder.typicode.com/posts",
        { userId: userId },
        function (posts) {
          var titles = posts.slice(0, 3).map(function (p) {
            return p.title.substring(0, 40) + "...";
          });
          $("#result").text(
            "Found " + posts.length + " posts for user " + userId +
            " — " + titles.join(" | ")
          );
        }
      );
    });
    Try It Yourself

    How It Works

    1. Read input. Take userId from the form.
    2. Encode. jQuery turns { userId } into ?userId=….
    3. Parse. Success gets an array of matching posts.
    4. Show. Display the count and a few titles.

    Example 4 — .done() / .fail() Error Handling

    Chain Promise handlers so 404s and parse errors are not silent.

    jQuery
    function loadUser(userId) {
      return $.getJSON("https://jsonplaceholder.typicode.com/users/" + userId)
        .done(function (user, textStatus, jqXHR) {
          $("#name").text(user.name);
          $("#status").text("Loaded (HTTP " + jqXHR.status + ")");
        })
        .fail(function (jqXHR, textStatus, errorThrown) {
          $("#name").text("User not found");
          $("#status").text("Error: " + textStatus + " — " + errorThrown);
        });
    }
    
    loadUser(1);          // success path
    // loadUser(99999);   // triggers .fail()
    Try It Yourself

    How It Works

    1. Return jqXHR. $.getJSON() returns a Promise-like object.
    2. Success. .done() runs with the parsed user.
    3. Failure. HTTP errors and bad JSON route to .fail().
    4. Avoid silent fails. Always chain .fail() for UI requests.

    Example 5 — $.getJSON() vs $.get(..., "json")

    Both produce the same parsed result — $.getJSON() is clearer for JSON-only calls.

    jQuery
    var url = "https://jsonplaceholder.typicode.com/albums/1";
    
    // A — dedicated JSON shorthand
    $.getJSON(url, function (album) {
      $("#title-a").text(album.title);
    });
    
    // B — $.get() with fourth dataType argument
    $.get(url, null, function (album) {
      $("#title-b").text(album.title);
    }, "json");
    
    // Both ≈ $.ajax({ url, dataType: "json", type: "GET", success: fn })
    Try It Yourself

    How It Works

    1. Same network. Both set dataType: "json" and GET the URL.
    2. Slot difference. $.get() needs null when you skip data.
    3. Same parse. Both success callbacks receive an object.
    4. Choose. Use $.getJSON() when JSON is always expected.

    Edge Cases & Pitfalls

    Check these before relying on $.getJSON() in production.

    silent

    Malformed JSON often fails silently

    Since jQuery 1.4, a syntax error usually skips success with no alert. Chain .fail() and validate server JSON.

    cors

    Same-origin still applies

    Cross-domain XHR needs CORS. JSONP (callback=?) can bypass that, but it is not a modern CORS replacement.

    jsonp

    JSONP success args may be undefined

    For JSONP / some cross-domain GETs, jqXHR and textStatus in success can be undefined — rely on the parsed data.

    removed

    Do not use .success() / .error()

    Those jqXHR methods were removed in jQuery 3.0. Use .done(), .fail(), and .always().

    strict

    JSON is stricter than JS object literals

    Property names and strings need double quotes. Trailing commas and single quotes break parsing.

    Browser Support

    jQuery.getJSON() has been part of jQuery since 1.0. Promise-style .done() / .fail() / .always() need jQuery 1.5+ (always since 1.6). It works in every browser that runs your loaded jQuery version.

    ✓ Stable · jQuery 1.0+

    jQuery.getJSON()

    Supported across jQuery 1.x, 2.x, and 3.x. Prefer a current jQuery 3.x build. Requires jQuery Ajax — native fetch() is a separate API.

    100% With jQuery Ajax
    Google Chrome All versions · Desktop & Mobile
    Full support
    Mozilla Firefox All versions · Desktop & Mobile
    Full support
    Apple Safari All versions · macOS & iOS
    Full support
    Microsoft Edge All versions · Chromium & Legacy
    Full support
    Internet Explorer IE 6+ · Legacy environments
    Full support
    Opera All modern versions
    Full support
    getJSON Universal

    Bottom line: Safe for everyday apps. Always chain .fail() so bad JSON and HTTP errors are visible.

    Performance Notes

    ApproachCostBest for
    $.getJSON() small payloadCheapTypical API records / lists
    Huge JSON + heavy DOM in successExpensivePaginate, virtualize, or stream
    Debounced search getJSONCheapTypeahead — abort stale jqXHR

    Parsing cost scales with payload size. Keep success handlers light, and abort outdated requests during fast typing.

    Key Takeaways

    • Role: GET shorthand with dataType: "json" — success gets a parsed value.
    • Call: $.getJSON(url [, data] [, success]) — returns jqXHR.
    • Errors: chain .fail() — bad JSON is often silent otherwise.
    • Modern: use .done() / .fail() / .always() — not removed 3.0 methods.

    One line: $.getJSON() is jQuery’s one-liner for GET + parse JSON — always pair it with .fail().

    Frequently Asked Questions

    jQuery.getJSON() is a shorthand for $.ajax() configured as a GET with dataType "json". Pass a URL, optional data, and optional success callback — jQuery parses the response into a JavaScript object or array and returns a jqXHR Promise.
    They are functionally the same. $.getJSON() presets dataType to "json"; $.get() takes "json" as a fourth argument. Prefer $.getJSON() when you always expect JSON — clearer intent, fewer arguments.
    $.getJSON() expands to $.ajax({ url, data, success, dataType: "json" }). Use getJSON for a simple JSON GET. Use $.ajax() when you need headers, beforeSend, POST, global: false, or other full settings.
    If the URL includes "callback=?" (or a similar server placeholder), jQuery treats the request as JSONP. That bypasses same-origin limits via a script tag. For JSONP, jqXHR and textStatus in the success callback may be undefined.
    Yes — since jQuery 1.4, a JSON syntax error usually fails silently: success never runs unless you chain .fail(), use a global ajaxError handler, or handle errors another way. Always chain .fail() for user-facing requests.
    A jqXHR object that implements jQuery’s Promise interface. Chain .done() for success, .fail() for errors, and .always() for either outcome. You can attach handlers after the request finishes; they still fire.

    Next: getScript() Method

    Load and execute a remote JavaScript file with jQuery’s script GET shorthand.

    getScript() tutorial →

    About the author

    Mari Selvan M P
    Mari Selvan M P 🔗

    Developer, cloud engineer, and technical writer

    • Experience 12 years building web and cloud systems
    • Focus Full Stack Development, AWS, and Developer Education

    I write practical tutorials so students and working developers can learn by doing—from databases and APIs to deployment on AWS.

    11 people found this page helpful