Modern web APIs almost universally return JSON. jQuery's $.getJSON() is a specialised shorthand that performs a GET request and automatically parses the response body as JSON, handing you a ready-to-use JavaScript object in the callback.
How It Works
Internally, $.getJSON(url, data, callback) is equivalent to $.ajax({ url, data, dataType: 'json', success: callback }). Because jQuery sets the Accept: application/json header, well-behaved APIs will also return JSON content-type automatically.
Consuming a Public API
Pair $.getJSON() with a public REST API to pull in live data — weather forecasts, GitHub repository info, or currency exchange rates — and render it dynamically without a page reload.
- Response is auto-parsed — no
JSON.parse()needed - Returns a
jqXHRobject for.done()/.fail()chaining - Supports JSONP via
callback=?in the URL (legacy cross-origin technique)
When the API returns an error status code (4xx, 5xx), jQuery triggers the .fail() handler, not the success callback, giving you clean separation of the happy path from error handling.