jQuery jQuery.parseJSON() Method

Beginner
⏱️ 9 min read
📚 Updated: Jul 2026
🎯 5 Examples
🚀 5 Try-it labs
JSON parsing

What You’ll Learn

The jQuery.parseJSON() utility converts a JSON string into a JavaScript value. This tutorial covers the official jQuery API example, parsing objects and arrays, error handling for malformed JSON, migration to JSON.parse(), and common pitfalls with quotes and control characters.

01

Syntax

$.parseJSON(s)

02

Objects

{ "key": val }

03

Arrays

[1, 2, 3]

04

Throws

Bad JSON errors

05

JSON.parse

Modern replacement

06

Removed

jQuery 4.0

Introduction

Web apps constantly exchange data as JSON text — API responses, configuration files, and localStorage entries all arrive as strings that must become JavaScript objects before your code can use them.

jQuery added jQuery.parseJSON() (also written $.parseJSON()) in version 1.4.1 as a consistent parsing helper, especially for $.ajax callbacks that returned JSON as text. It was deprecated in jQuery 3.0 and removed in jQuery 4.0 in favor of the native JSON.parse() method built into every modern browser.

Understanding the jQuery.parseJSON() Method

jQuery.parseJSON(json) accepts one argument: a string containing valid JSON. It returns the parsed value — which may be an object, array, string, number, boolean, or null. It does not modify the original string.

JSON has strict rules: object keys must use double quotes, strings must use double quotes, and values like undefined or NaN are not allowed. Passing malformed JSON throws an exception — unlike some loose parsers, jQuery does not silently fix bad input.

💡
Beginner Tip

JSON is a text format, not a JavaScript object literal. Writing {name: "John"} works in JS but is invalid JSON — keys need quotes: {"name": "John"}.

📝 Syntax

General form of jQuery.parseJSON:

jQuery
jQuery.parseJSON( json )
// or
$.parseJSON( json )

Parameters

  • json — a string containing well-formed JSON to parse.

Return value

  • The JavaScript value represented by the JSON string (object, array, string, number, boolean, or null).
  • Throws a SyntaxError when the string is not valid JSON.

Official jQuery API example

jQuery
var obj = jQuery.parseJSON('{ "name": "John" }');
console.log(obj.name === "John"); // true

⚡ Quick Reference

GoalCode
Parse JSON (jQuery)$.parseJSON(str)
Parse JSON (native)JSON.parse(str)
Safe parse with fallbacktry { JSON.parse(str) } catch (e) { }
Stringify back to JSONJSON.stringify(obj)
Invalid JSON?Throws SyntaxError
Status in jQuery 4+Removed — use JSON.parse

📋 $.parseJSON vs JSON.parse vs eval

Three ways to turn text into data — very different safety profiles.

parseJSON
$.parseJSON

jQuery 1.4+; removed in 4.0

JSON.parse
native

ES5+; use this today

eval
never

Runs arbitrary code — unsafe

ajax
dataType

jQuery can auto-parse JSON

Examples Gallery

Example 1 matches the official jQuery API documentation. Use DevTools or the Try-it links to run each snippet.

📚 Getting Started

Parse JSON objects and read properties.

Example 1 — Official jQuery API Demo

Parse a JSON object string and verify the name property — exactly as documented on the jQuery API page.

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

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

How It Works

The JSON string uses double-quoted keys and values as required by the JSON spec. parseJSON returns a plain object you can access with dot or bracket notation.

📈 Practical Patterns

Arrays, AJAX data, error handling, and modern migration.

Example 2 — Parse a JSON Array

JSON arrays parse into JavaScript arrays you can loop with $.each or forEach.

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

Top-level JSON can be an array or an object. After parsing, use normal array methods — length, indexing, map, and so on.

Example 3 — Parse an API Response Object

Typical pattern: receive JSON text from a server, parse it, then read nested fields.

jQuery
var responseText = '{"status":"ok","user":{"id":42,"email":"dev@codetofun.com"}}';
var data = $.parseJSON(responseText);

console.log(data.status);       // "ok"
console.log(data.user.id);      // 42
console.log(data.user.email);   // "dev@codetofun.com"
Try It Yourself

How It Works

Before dataType: "json" was universal, developers called $.parseJSON(xhr.responseText) inside $.ajax success handlers. The parsed object mirrors the server’s nested structure.

Example 4 — Malformed JSON Throws an Error

Invalid JSON — unquoted keys, single quotes, or forbidden values — causes an exception.

jQuery
var badSamples = [
  '{test: 1}',           // keys need double quotes
  "{'test': 1}",        // single quotes invalid
  '"undefined"',         // undefined not allowed in JSON
  '".1"'                 // number needs leading digit
];

badSamples.forEach(function (sample) {
  try {
    $.parseJSON(sample);
    console.log("Unexpected success:", sample);
  } catch (err) {
    console.log("Rejected:", sample.slice(0, 12) + "...");
  }
});
Try It Yourself

How It Works

The jQuery API documents these invalid forms explicitly. Always wrap parsing in try/catch when the string comes from a network, file, or user — never assume it is valid JSON.

Example 5 — Migrate to Native JSON.parse()

Modern equivalent with the same behavior — the recommended path for jQuery 3+ and jQuery 4.

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

// Legacy jQuery (3.x still has it; removed in 4.0)
var withJquery = $.parseJSON(json);

// Modern native — use this in new code
var withNative = JSON.parse(json);

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

How It Works

When the browser provides JSON.parse, jQuery used it internally for $.parseJSON. A straight find-and-replace to JSON.parse is the standard migration — add try/catch where missing.

🚀 Common Use Cases

  • AJAX text responses — parse responseText before jQuery auto-parsed JSON with dataType: "json".
  • localStorage / sessionStorage — convert stored JSON strings back into objects.
  • Configuration files — load JSON settings embedded in script tags or fetched at runtime.
  • Plugin options — parse JSON from data-* attributes on DOM elements.
  • Legacy code maintenance — read and refactor older jQuery projects using $.parseJSON.
  • Validation pipelines — try/catch around parse to detect corrupt server output early.

🧠 How jQuery.parseJSON() Parses a String

1

Receive JSON string

Input must be a string — not an already-parsed object.

Input
2

Validate format

Strict JSON rules — double quotes, no trailing commas, no undefined.

Validate
3

Native parse

jQuery delegates to JSON.parse when the browser supports it.

Parse
4

Return JS value

Object, array, string, number, boolean, or null — ready to use in your app.

📝 Notes

  • Available since jQuery 1.4.1; deprecated in jQuery 3.0; removed in jQuery 4.0.
  • Use JSON.parse() in all new code — identical behavior on valid JSON.
  • Prior to jQuery 1.9, empty string / null / undefined input returned null instead of throwing.
  • Literal tab/newline inside JSON strings can break parsing — escape backslashes in server output.
  • Never use eval() to parse JSON — it executes arbitrary JavaScript.
  • Pair with JSON.stringify() when writing values back to storage or APIs.

Browser Support

jQuery.parseJSON() existed in jQuery 1.4.1 through 3.x and was removed in jQuery 4.0. Native JSON.parse() is supported in all modern browsers since ES5 (2009) and in Node.js.

Deprecated · jQuery 3.0

jQuery jQuery.parseJSON()

Works in jQuery 1.x–3.x. Native JSON.parse is supported in Chrome, Firefox, Safari, Edge, IE8+, and all current runtimes.

100% Native JSON.parse support
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
JSON.parse() Universal

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

Conclusion

The jQuery.parseJSON() utility converts well-formed JSON strings into JavaScript values. It was essential in early jQuery AJAX workflows and remains important to recognize when reading older codebases.

For modern development, use native JSON.parse() with try/catch error handling. Remember JSON’s strict syntax rules and never parse untrusted strings with eval().

💡 Best Practices

✅ Do

  • Use JSON.parse() in new JavaScript code
  • Wrap parsing in try/catch for external data
  • Validate server JSON with double-quoted keys and strings
  • Use dataType: "json" in $.ajax when possible
  • Replace $.parseJSON before upgrading to jQuery 4

❌ Don’t

  • Parse JavaScript object literals — they are not JSON
  • Use eval() to parse JSON strings
  • Assume AJAX responses are valid JSON without error handling
  • Include literal tabs/newlines unescaped in JSON strings
  • Depend on $.parseJSON in jQuery 4+ projects

Key Takeaways

Knowledge Unlocked

Five things to remember about jQuery.parseJSON()

Turn JSON text into usable JavaScript values.

5
Core concepts
🔢 02

Strict

Valid JSON only

Rules
03

Throws

Bad input errors

Errors
🔄 04

JSON.parse

Modern API

Migrate
🔒 05

No eval

Safe parsing

Security

❓ Frequently Asked Questions

jQuery.parseJSON(json) takes a well-formed JSON string and returns the corresponding JavaScript value — an object, array, string, number, boolean, or null. It is the jQuery-era wrapper around JSON parsing used heavily with $.ajax before responseType: json was universal.
The jQuery API demo is: var obj = jQuery.parseJSON('{ "name": "John" }'); alert(obj.name === "John"); — which parses a JSON object string and reads the name property.
Both parse valid JSON strings into JavaScript values. jQuery.parseJSON() was deprecated in jQuery 3.0 and removed in jQuery 4.0. Modern code should use native JSON.parse(). When available, jQuery delegated to JSON.parse internally anyway.
jQuery.parseJSON() throws a JavaScript exception — same as JSON.parse(). Invalid examples include unquoted keys ({test: 1}), single-quoted strings, undefined, NaN, and numbers like .1 without a leading zero. Always wrap parsing in try/catch for external data.
No. Use JSON.parse() in all new code. jQuery removed $.parseJSON in version 4.0. Migrate legacy $.parseJSON(str) calls to JSON.parse(str) with try/catch error handling.
The JSON standard forbids literal control characters inside strings. A value like {"testing":"1\t2\n3"} can fail because the parser sees real tab/newline characters. Escape backslashes in server-generated JSON: "1\\t2\\n3" produces the intended \t and \n sequences in the parsed string.
Did you know?

Before jQuery 1.9, $.parseJSON("") returned null instead of throwing — even though an empty string is not valid JSON. Modern JSON.parse("") throws a SyntaxError. When migrating old code, audit every parse call that relied on the silent null fallback.

Continue to jQuery.proxy()

Learn how to lock function context for event handlers and callbacks.

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.

6 people found this page helpful