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
Fundamentals
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.
Concept
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"}.
Foundation
📝 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.
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"
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) + "...");
}
});
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
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.
Applications
🚀 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.
Important
📝 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.
Compatibility
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 ChromeAll versions · Desktop & Mobile
Full support
Mozilla FirefoxAll versions · Desktop & Mobile
Full support
Apple SafariAll versions · macOS & iOS
Full support
Microsoft EdgeAll versions · Chromium & Legacy
Full support
Internet ExplorerIE 6+ · Legacy environments
Full support
OperaAll 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.
Wrap Up
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().
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
Summary
Key Takeaways
Knowledge Unlocked
Five things to remember about jQuery.parseJSON()
Turn JSON text into usable JavaScript values.
5
Core concepts
📝01
parseJSON
String → value
API
🔢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.