jQuery getJSON() Method

Beginner
5 min read
Updated: Nov 2026
3 examples
Ajax

Definition

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().

Syntax

Start with these common calls. Keep them short and readable.

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

// Returns jqXHR → chain .done() / .fail() / .always()
CallWhat it does
jQueryLearn jQuery.getJSON(): the JSON GET shorthand for $.ajax(), url/data/success signatures, parsed object callbacks, query-string data, JSONP with callback=?, jqXHR done/fail/always chaining, and silent malformed JSON pitfalls.

Load jQuery before your script (CDN or local file), then wrap DOM work in $(function () { ... }) when needed.

Parameters

ParameterDescription
Step 1Call $.getJSON(url) with an optional data object and/or success callback.
Step 2jQuery sends a GET; data becomes a query string.
Step 3On success, the callback receives a parsed object or array.

Return Value

Return ValueDescription
jQuery objectMost setters and traversing helpers return the jQuery collection so you can chain more methods.
Value / undefinedGetters usually return a value from the first matched element, or undefined when nothing applies.

jQuery Examples

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.

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.

    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.

    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: jQuery.getScript() Method

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

    jQuery.getScript() Method tutorial →

    CODETOFUN NEWS

    Stay Ahead in Tech

    Get the latest IT news, programming updates, and technology trends directly on your phone.

    Your daily dose of tech, straight to your feed.

    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