jQuery parseJSON() Method

Beginner
5 min read
Updated: Nov 2026
3 examples
Utilities

Definition

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.

Syntax

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

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

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

// Modern equivalent:
obj = JSON.parse('{ "name": "John" }')
CallWhat it does
jsonWell-formed JSON string to parse
ReturnJavaScript value (object, array, primitive, or null)
On errorThrows (same idea as JSON.parse)

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

Parameters

ParameterDescription
Step 1Start with a well-formed JSON string (double-quoted keys and strings).
Step 2Call $.parseJSON(str) — or JSON.parse(str) in new code.
Step 3Use the returned value like any object or array.

Return Value

Return ValueDescription
BooleanOften true or false depending on the match or state.
Value / undefinedGetters usually return a value from the first matched element, or undefined when nothing applies.

jQuery Examples

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.

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

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.

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

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

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

9 people found this page helpful