JSON.parse() is a JavaScript method used to convert a valid JSON string into a JavaScript object or value. It is essential when working with data received from APIs, stored in localStorage, or loaded from JSON files.

Key Points:

  • Syntax: JSON.parse(text[, reviver])

    • text: The JSON string to parse.

    • reviver (optional): A function that transforms the parsed values before returning them.

  • Returns: A JavaScript object, array, string, number, boolean, or null, depending on the JSON content.

  • Throws: SyntaxError if the input string is not valid JSON (e.g., invalid syntax, trailing commas, single quotes instead of double quotes).

  • Use Cases:

    • Parsing API responses: fetch('/api/data').then(res => res.json()).then(data => console.log(JSON.parse(data)))

    • Retrieving stored data: const user = JSON.parse(localStorage.getItem('user'))

    • Converting JSON strings to usable JavaScript objects.

Example:

const jsonString = '{"name": "Alice", "age": 30}';
const obj = JSON.parse(jsonString);
console.log(obj.name); // Output: "Alice"

Advanced Use: Reviver Function

The reviver function allows you to modify values during parsing:

const json = '{"date": "2025-01-01"}';
const obj = JSON.parse(json, (key, value) => {
  if (key === 'date') return new Date(value);
  return value;
});
console.log(obj.date); // Output: Date object

⚠️ Note: Always validate JSON input before parsing to avoid runtime errors. Use try...catch for robust error handling.

A Javascript object is a data type in Javascript - it's have property and value pair as you define in your first example.

var ab = {"name":"abcd", "details":{"address":"pqrst", "Phone":1234567890}};

Now What is Json : A JSON string is a data interchange format - it is nothing more than a bunch of characters formatted a particular way (in order for different programs to communicate with each other)

var pq = '{"name":"abcd", "details":{"address":"pqrst", "Phone":1234567890}}';

so it's is a String With json Format.

and at last JSON.parse() Returns the Object corresponding to the given JSON text.

Answer from Shailendra Sharma on Stack Overflow
🌐
MDN Web Docs
developer.mozilla.org › en-US › docs › Web › JavaScript › Reference › Global_Objects › JSON › parse
JSON.parse() - JavaScript | MDN
The JSON.parse() static method parses a JSON string, constructing the JavaScript value or object described by the string. An optional reviver function can be provided to perform a transformation on the resulting object before it is returned.
🌐
JSON Formatter
jsonformatter.org › json-parser
JSON Parser Online to parse JSON
Online JSON Parser helps to parse, view, analyze JSON data in Tree View.
Discussions

How does JSON.parse() work?
I have not worked too much on javascript. And, I need to parse a JSON string. So, I want to know what exactly JSON.parse does. For example : If I assign a json string to a variable like this, var ... More on stackoverflow.com
🌐 stackoverflow.com
Parse json
If you do not want your HTTP module to parse the JSON directly (perhaps because you need to manipulate the input in some way), then you use a Parse JSON module to convert the text returned from the HTTP module into a JSON object · Make is capable of more complex manipulation if you need it. More on community.make.com
🌐 community.make.com
1
0
January 23, 2024
Is JSON.parse() safe? Or Am I leaving myself exposed to injection attacks?
JSON can’t have functions in it, only data. As long as you’re not concatenating any strings into functions you should be good. More on reddit.com
🌐 r/learnjavascript
13
30
July 10, 2022
parse JSON manually
Given these functions, write a ... parseNull, if {, call parseObject etc. . Note that parseArray and parseObject will call parse themselves. ... There may be reasons to use a custom JSON parsing method but in case this was what you were looking for...... More on stackoverflow.com
🌐 stackoverflow.com
🌐
W3Schools
w3schools.com › js › js_json_parse.asp
JSON.parse()
A common use of JSON is to exchange data to/from a web server. When receiving data from a web server, the data is always a string. Parse the data with JSON.parse(), and the data becomes a JavaScript object.
🌐
Json Parser Online
json.parser.online.fr
Json Parser Online
Analyze your JSON string as you type with an online Javascript parser, featuring tree view and syntax highlighting. Processing is done locally: no data send to server.
Find elsewhere
🌐
Alteryx
help.alteryx.com › current › en › designer › tools › developer › json-parse-tool.html
JSON Parse Tool
Use JSON Parse to separate JavaScript Object Notation (JSON) text into a table schema for downstream processing.
🌐
Jsongrid
jsongrid.com › json-parser
Json Parser Online - All-in-One Solution
Json Parser is the online tool to parse Json. Json could be very complex sometimes. If it's not formatted, it's really hard to understand the entire tree structure of it.
🌐
GeeksforGeeks
geeksforgeeks.org › javascript › javascript-json-parse-method
JavaScript JSON parse() Method - GeeksforGeeks
July 11, 2025 - The JSON.parse() method is used to convert a JSON string into a JavaScript object.
🌐
DigitalOcean
digitalocean.com › community › tutorials › js-json-parse-stringify
How To Use JSON.parse() and JSON.stringify() | DigitalOcean
November 24, 2021 - JSON.parse() takes a JSON string and transforms it into a JavaScript object.
🌐
Sigmacomputing
quickstarts.sigmacomputing.com › guide › tables_json_parsing › index.html
Parsing JSON Data in Seconds
For many business users, JSON can be frustrating because it typically requires a developer or ETL tool to flatten it into a more familiar columnar format. This adds time and requires technical expertise. Sigma provides a much better way: you can directly and easily parse JSON inside Sigma, without waiting for developer intervention.
🌐
JSON Editor Online
jsoneditoronline.org › home › parse › parse-json
Parse JSON: What is JSON parsing and how does it work? | Indepth
August 23, 2022 - When you parse JSON, you convert a string containing a JSON document into a structured data object that you can operate on. Learn how this works.
🌐
MetaCPAN
metacpan.org › dist › JSON-Parse › view › lib › JSON › Parse.pod
JSON::Parse - Parse JSON - metacpan.org
This switches on "copy_literals" so that JSON true, false and null values are copied. These values can be modified, but they will not be converted back into true and false by JSON::Create. ... Parsing errors are reported by "carp" in Carp, so the error line number refers to the caller's line.
Top answer
1 of 4
4
var json = Function("return {\
foo: {\
  bar: 'something',\
  baz: {\
    jack: 'other',\
    jill: 5\
  },\
  bob: {\
    bill: 'hello',\
    bilbo: 11,\
      baggins: {\
        fizz: 'buzz'\
      }\
    }\
  }\
}")(); // object
2 of 4
3

Building upon phihag's answer, I just made this up. It might be a start for you.

It does not support:

  • Spaces outside key/value
  • Any of ,{}:" as key/value
  • Arrays
  • No error handling
  • (Probably more - I haven't tested this extensively)

The code:

var json = '{"a":{"b":"test"},"c":123,"d":{"nested":{"key":null}}}';

var split = function(str, delimiter, func) {
    var res = [];
    var before = 0;
    for(var i = 0; i < str.length; i++) {
        if(str[i] === delimiter) {
            if(func(str, i) === true) {
                res.push(str.substring(before, i));
                before = i + 1;
            }
        }
    }
    res.push(str.substring(before));
    return res;
};

var amountbefore = function(str, pos, character) {
    var amount = 0;
    for(var i = 0; i < pos; i++) {
        if(str[i] === character) {
            amount++;
        }
    }
    return amount;
};

var parse = function(obj) {
    var stripped = obj.slice(1, -1);
    var splitted = split(stripped, ",", function(str, i) {
        return amountbefore(str, i, "{") === amountbefore(str, i, "}");
    });
    var res = {};
    if(stripped === "") return res;
    for(var i = 0; i < splitted.length; i++) {
        var spl = split(splitted[i], ":", function(str, i) {
            return amountbefore(str, i, "{") === amountbefore(str, i, "}")
        });
        var val;
        if(spl[1][0] === "n")     val = null;
        if(/^\d/.test(spl[1][0])) val = spl[1] - 0;
        if(spl[1][0] === "\"")    val = spl[1].slice(1, -1);
        if(spl[1][0] === "{")     val = parse(spl[1]);
        res[spl[0].slice(1, -1)] = val;
    }
    return res;
};

parse(json); // parses the JSON string
🌐
Jsoniter
jsoniter.com
Fastest JSON parser ever
jsoniter (json-iterator) is fast and flexible JSON parser available in Java and Go.
🌐
Json-ld
json-ld.org
JSON-LD - JSON for Linked Data
The JSON-LD Playground is a web-based JSON-LD viewer and debugger. If you are interested in learning JSON-LD, this tool will be of great help to you. Developers may also use the tool to debug, visualize, and share their JSON-LD markup.
🌐
Python
docs.python.org › 3 › library › json.html
json — JSON encoder and decoder
5 days ago - Disable escaping of non-ascii characters, see json.dumps() for more information. Added in version 3.9. ... Parse every input line as separate JSON object.