jQuery parseJSON() Method

Beginner
6 min read
Updated: Oct 2026
4 examples
Live preview

What Is parseJSON()?

jQuery.parseJSON(json) (alias $.parseJSON) takes a well-formed JSON string and returns the matching JavaScript value (added in jQuery 1.4.1). When the browser has native JSON.parse, jQuery uses it under the hood.

Remember
$.parseJSON(jsonString)  → object | array | string | number | boolean | null

obj = $.parseJSON('{ "name": "John" }')
obj.name === "John"   // true

// Modern equivalent:
obj = JSON.parse('{ "name": "John" }')
NeedUse
Parse JSON (legacy jQuery)$.parseJSON(str)
Parse JSON (new code)JSON.parse(str)
Parse HTML fragments$.parseHTML(str)
Parse XML feeds$.parseXML(str)

How to Use parseJSON()

Parse once, read properties, and catch errors on external data.

  1. Start with a well-formed JSON string (double-quoted keys and strings).
  2. Call $.parseJSON(str) — or JSON.parse(str) in new code.
  3. Use the returned value like any object or array.
  4. Wrap untrusted or API text in try/catch — bad JSON throws.
PieceRequired?Role
jsonYesWell-formed JSON string to parse
Return—JavaScript value (object, array, primitive, or null)
On error—Throws (same idea as JSON.parse)

Pseudocode

Pseudocode
function parseJSON(json):
    // use native JSON.parse when available
    return JSON.parse(json)

// Typical flow:
try:
    data = $.parseJSON(responseText)   // or JSON.parse(...)
    use data.name / data.items
catch error:
    handle bad JSON

Cheat Sheet

Keep these facts handy while parsing JSON with jQuery.

TopicDetail
SyntaxjQuery.parseJSON(json) / $.parseJSON(json)
SincejQuery 1.4.1
StatusDeprecated 3.0 · removed 4.0
InputWell-formed JSON String
OutputObject, Array, String, Number, Boolean, or null
Modern replacementJSON.parse(str)
HTML / XML siblingsparseHTML, parseXML

Live Preview

Pick a sample JSON string, parse it with $.parseJSON, and inspect the result.

Browser demo of $.parseJSON() — same ideas as the examples below.

Result
sample = Object (John)
name → "John"
name === "John" → true

jQuery Examples

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

Example 1 — Official Demo

Official jQuery API pattern in a few lines.

jQuery
var obj = $.parseJSON('{ "name": "John" }');

console.log(obj.name);              // "John"
console.log(obj.name === "John");   // true
Try It Yourself

How It Works

  1. JSON text. Keys and strings use double quotes — required by JSON.
  2. Parse. $.parseJSON(...) returns a plain object { name: "John" }.
  3. Read. obj.name is normal JavaScript property access.
  4. Check. The equality test matches the official API demo.

Example 2 — Parse a JSON Array

JSON arrays become real JavaScript arrays.

jQuery
var json = '["HTML", "CSS", "JavaScript"]';
var langs = $.parseJSON(json);

console.log(langs.length);  // 3
console.log(langs[1]);      // "CSS"
Try It Yourself

How It Works

  1. Input. Square brackets mark a JSON array of three strings.
  2. Parse. langs is a real array with .length and indexes.
  3. Index 1. Zero-based indexing makes langs[1] equal "CSS".
  4. Use. Loop with .forEach or jQuery $.each as needed.

Example 3 — Catch Invalid JSON

Malformed JSON throws — always catch external data.

jQuery
var samples = ["{test: 1}", "{'test': 1}", '".1"'];

samples.forEach(function (sample) {
  try {
    $.parseJSON(sample);
    console.log("ok:", sample);
  } catch (err) {
    console.log("rejected:", sample);
  }
});
Try It Yourself

How It Works

  1. Unquoted key. {test: 1} is JavaScript object syntax, not JSON.
  2. Single quotes. JSON requires double quotes for strings and keys.
  3. Leading dot. .1 is invalid — use 0.1.
  4. try/catch. Bad API text should not crash the page.

Example 4 — Migrate to JSON.parse()

Same valid JSON — prefer the native API in new code.

jQuery
var json = '{ "title": "CodeToFun", "year": 2026 }';

var withJquery = $.parseJSON(json);
var withNative = JSON.parse(json);

console.log(withJquery.title === withNative.title);  // true
console.log(withNative.year);                        // 2026
Try It Yourself

How It Works

  1. Same input. One JSON string is parsed two ways.
  2. Legacy. $.parseJSON still works on jQuery 3.x.
  3. Native. JSON.parse is the supported replacement (and what jQuery used internally).
  4. Migrate. Replace $.parseJSON(str) with JSON.parse(str) and keep try/catch.

Edge Cases & Pitfalls

Check these before parsing real API responses.

deprecated

Removed in jQuery 4.0

Do not start new features on $.parseJSON. Use JSON.parse so upgrades stay smooth.

quotes

JSON is stricter than JS object literals

Keys and strings need double quotes. Single quotes, trailing commas, undefined, and NaN are invalid.

control chars

Literal tabs/newlines inside strings fail

When building JSON in JS source, double backslashes ("1\\t2\\n3") so escapes survive into the JSON text.

legacy

Empty input before jQuery 1.9

Old jQuery returned null for "" / null / undefined. Modern JSON.parse("") throws — audit migrations.

Browser Support

jQuery.parseJSON() existed in jQuery 1.4.1–3.x and was removed in jQuery 4.0. Prefer native JSON.parse() in all modern browsers. This page focuses on browser use with jQuery loaded.

✓ Deprecated · jQuery 3.x

jQuery.parseJSON()

Available with jQuery 1.4.1–3.x in Chrome, Firefox, Safari, and Edge. Prefer JSON.parse() for new code. Not present in jQuery 4.0.

Legacy jQuery 3.x only
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
$.parseJSON() Legacy

Bottom line: Learn $.parseJSON() for legacy jQuery code. Write JSON.parse(str) in new projects and before upgrading to jQuery 4.

Performance Notes

ApproachCostBest for
JSON.parse(str)O(n) in string sizeAll new code
$.parseJSON(str)Same (delegates to native)Legacy jQuery 1.x–3.x only
Re-parse the same stringWastefulAvoid — parse once, reuse the value

Parsing cost tracks string length. Prefer one parse per response, then pass the object around. There is no speed win to keeping $.parseJSON over JSON.parse.

Key Takeaways

  • Role: $.parseJSON(str) → JavaScript value from JSON text.
  • Modern: use JSON.parse(str) instead.
  • Errors: malformed JSON throws — use try/catch.
  • Status: deprecated in 3.0, removed in 4.0.

One line: know $.parseJSON for legacy jQuery, but parse with JSON.parse and try/catch in every new project.

Frequently Asked Questions

jQuery.parseJSON(json) takes a well-formed JSON string and returns the matching JavaScript value — an object, array, string, number, boolean, or null. It was the jQuery helper for parsing JSON text before dataType: "json" and native JSON.parse were universal.
The jQuery API demo is: var obj = jQuery.parseJSON('{ "name": "John" }'); then check obj.name === "John". It parses a small JSON object and reads a property.
Both parse valid JSON into JavaScript values. When the browser provides JSON.parse, jQuery uses it internally. Prefer native JSON.parse in all new code — $.parseJSON was deprecated in jQuery 3.0 and removed in jQuery 4.0.
$.parseJSON throws a JavaScript exception (same as JSON.parse). Invalid examples include unquoted keys, single quotes, undefined, NaN, and numbers like .1 without a leading zero. Wrap external data in try/catch.
No. Use JSON.parse() for new work. Keep $.parseJSON only while maintaining jQuery 1.x–3.x legacy code. Migrate before upgrading to jQuery 4.
JSON forbids literal control characters inside strings. If a server injects a JS string with real tab/newline characters, parsing fails. Double the backslashes ("1\\t2\\n3") so the JSON text keeps the escape sequences.
Prior to jQuery 1.9, $.parseJSON returned null for an empty string, null, or undefined instead of throwing — even though those are not valid JSON. Modern JSON.parse("") throws a SyntaxError.

Next: proxy()

Learn how jQuery locks a function’s this context for handlers.

proxy 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.

9 people found this page helpful