🌐
W3Schools
w3schools.com › js › js_json_parse.asp
JSON.parse()
Parse the data with JSON.parse(), and the data becomes a JavaScript object.
🌐
W3Schools
w3schools.com › jsref › jsref_parse_json.asp
JavaScript JSON parse() Method
The JSON.parse() method parses a string and returns a JavaScript object.
🌐
MDN Web Docs
developer.mozilla.org › en-US › docs › Web › JavaScript › Reference › Global_Objects › JSON › parse
JSON.parse() - JavaScript | MDN
The string to parse as JSON. See the JSON object for a description of JSON syntax. ... If a function, this prescribes how each value originally produced by parsing is transformed before being returned. Non-callable values are ignored.
🌐
W3Schools
w3schools.io › file › json-javascript
Javascript to parse, write, pretty json file(Examples) - w3schools
<script> const jsonString=[{"name":"eric","id":"1"}, {"name":"andrew","id":"2"},{"name":"john","id":"3"}, {"name":"Flintoff","id":"4"},{"name":"Greg","id":"5"}, {"name":"Francis","id":"6"}]; console.log(JSON.stringify(jsonString,null,3)); </script>
🌐
W3Schools
w3schools.com › jsref › jsref_obj_json.asp
JavaScript JSON Reference
// Storing data: myObj = { "name":"John", "age":31, "city":"New York" }; myJSON = JSON.stringify(myObj); localStorage.setItem("testJSON", myJSON); // Retrieving data: text = localStorage.getItem("testJSON"); obj = JSON.parse(text); document.getElementById("demo").innerHTML = obj.name; Try it Yourself » · Learn more about JSON in our JSON tutorial. ... If you want to use W3Schools services as an educational institution, team or enterprise, send us an e-mail: sales@w3schools.com · If you want to report an error, or if you want to make a suggestion, send us an e-mail: help@w3schools.com · HTML Tutorial CSS Tutorial JavaScript Tutorial How To Tutorial SQL Tutorial Python Tutorial W3.CSS Tutorial Bootstrap Tutorial PHP Tutorial Java Tutorial C++ Tutorial jQuery Tutorial
🌐
W3Schools
w3schools.com › js › js_json.asp
JavaScript JSON
JavaScript has a built in function for converting JSON strings into JavaScript objects: ... You can receive pure text from a server and use it as a JavaScript object. You can send a JavaScript object to a server in pure text format.
🌐
Tutorial Republic
tutorialrepublic.com › javascript-tutorial › javascript-json-parsing.php
JavaScript JSON Parsing - Tutorial Republic
JSON is the most popular and lightweight data-interchange format for web applications. In JavaScript, you can easily parse JSON data received from the web server using the JSON.parse() method.
🌐
W3Schools Blog
w3schools.blog › home › json.parse() method
JSON.parse() method - W3schools
May 19, 2019 - <!DOCTYPE html> <html> <body> <script> var details = '{ "Name":"JAI", "Seat":"56", "Coach":"5A"}'; var passenger = JSON.parse(details); document.write(passenger.Name + " " + passenger.Seat); </script> </body> </html>
🌐
W3Schools
w3schools.com › js › tryit.asp
W3Schools online HTML editor
The W3Schools online code editor allows you to edit code and view the result in your browser
Find elsewhere
🌐
W3Schools
w3schools.com › js › tryit.asp
W3Schools Tryit Editor - Create Object from JSON String
The W3Schools online code editor allows you to edit code and view the result in your browser
🌐
W3Schools
w3schools.com › js › js_json_arrays.asp
JSON Arrays
In JSON, array values must be of type string, number, object, array, boolean or null. In JavaScript, array values can be all of the above, plus any other valid JavaScript expression, including functions, dates, and undefined. ... If you want to use W3Schools services as an educational institution, team or enterprise, send us an e-mail: sales@w3schools.com
🌐
W3Schools
w3schools.com › js › js_json_server.asp
JSON Server
Parse the data with JSON.parse(), and the data becomes a JavaScript object.
🌐
MDN Web Docs
developer.mozilla.org › en-US › docs › Learn_web_development › Core › Scripting › JSON
Working with JSON - Learn web development | MDN
If you load this JSON in your JavaScript program as a string, you can parse it into a normal object and then access the data inside it using the same dot/bracket notation we looked at in the JavaScript object basics article.
Top answer
1 of 16
2044

The standard way to parse JSON in JavaScript is JSON.parse()

The JSON API was introduced with ES5 (2011) and has since been implemented in >99% of browsers by market share, and Node.js. Its usage is simple:

const json = '{ "fruit": "pineapple", "fingers": 10 }';
const obj = JSON.parse(json);
console.log(obj.fruit, obj.fingers);


The only time you won't be able to use JSON.parse() is if you are programming for an ancient browser, such as IE 7 (2006), IE 6 (2001), Firefox 3 (2008), Safari 3.x (2009), etc. Alternatively, you may be in an esoteric JavaScript environment that doesn't include the standard APIs. In these cases, use json2.js, the reference implementation of JSON written by Douglas Crockford, the inventor of JSON. That library will provide an implementation of JSON.parse().

When processing extremely large JSON files, JSON.parse() may choke because of its synchronous nature and design. To resolve this, the JSON website recommends third-party libraries such as Oboe.js and clarinet, which provide streaming JSON parsing.

jQuery once had a $.parseJSON() function, but it was deprecated with jQuery 3.0. In any case, for a long time, it was nothing more than a wrapper around JSON.parse().

2 of 16
107

WARNING!

This answer stems from an ancient era of JavaScript programming during which there was no builtin way to parse JSON. The advice given here is no longer applicable and probably dangerous. From a modern perspective, parsing JSON by involving jQuery or calling eval() is nonsense. Unless you need to support IE 7 or Firefox 3.0, the correct way to parse JSON is JSON.parse().

First of all, you have to make sure that the JSON code is valid.

After that, I would recommend using a JavaScript library such as jQuery or Prototype if you can because these things are handled well in those libraries.

On the other hand, if you don't want to use a library and you can vouch for the validity of the JSON object, I would simply wrap the string in an anonymous function and use the eval function.

This is not recommended if you are getting the JSON object from another source that isn't absolutely trusted because the eval function allows for renegade code if you will.

Here is an example of using the eval function:

var strJSON = '{"result":true,"count":1}';
var objJSON = eval("(function(){return " + strJSON + ";})()");
alert(objJSON.result);
alert(objJSON.count);

If you control what browser is being used or you are not worried people with an older browser, you can always use the JSON.parse method.

This is really the ideal solution for the future.

🌐
W3Schools
w3schoolsua.github.io › js › js_json_intro_en.html
JSON - Introduction. Lessons for beginners. W3Schools in English
JavaScript has a built-in function for converting JSON strings into JavaScript objects: ... You can receive pure text from a server and use it as a JavaScript object. You can send a JavaScript object to a server in pure text format.
🌐
GeeksforGeeks
geeksforgeeks.org › javascript › javascript-json-parse-method
JavaScript JSON parse() Method - GeeksforGeeks
July 11, 2025 - It converts a JSON string into a JavaScript object. Throws a SyntaxError if the input string is not valid JSON. Accepts an optional reviver function to transform the parsed data.
🌐
W3Schools
w3schools.com › js › js_json_objects.asp
JSON Literals
JSON Intro JSON Syntax JSON vs XML JSON Data Types JSON Parse JSON Stringify JSON Objects JSON Arrays JSON Server JSON PHP JSON HTML JSON JSONP JS jQuery
🌐
W3Schools
w3schools.com › js › js_json_html.asp
JSON HTML
JavaScript can be used to make HTML in your web pages. ... const dbParam = JSON.stringify({table:"customers",limit:20}); const xmlhttp = new XMLHttpRequest(); xmlhttp.onload = function() { myObj = JSON.parse(this.responseText); let text = "<table border='1'>" for (let x in myObj) { text += "<tr><td>" + myObj[x].name + "</td></tr>"; } text += "</table>" document.getElementById("demo").innerHTML = text; } xmlhttp.open("POST", "json_demo_html_table.php"); xmlhttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded"); xmlhttp.send("x=" + dbParam); Try it Yourself »
Top answer
1 of 3
3

This algorithm is pretty straightforward--something like the following should work:

function parse(a) {
  //create object to return
  var ret = {
    columns: [],
    data: []
  };

  //iterate the source array
  a.forEach(function(item, i) {
    if (i === 0) {
      //first time through, build the columns
      for (var key in item) {
        ret.columns.push(key);
      }
    }

    //now build your data item
    ret.data[i] = [];

    //use the column array to guarantee that the order of the fields in the source string doesn't matter
    for (var j = 0; j < ret.columns.length; j++) {
      var key = ret.columns[j];
      ret.data[i].push(item[key]);
    }
  });
  return ret;
}

var j = {
  "d": "[{\"ID\":\"VN00000123\",\"NAME\":\"JOHN GREEN\",\"GENDER\":\"Male\",\"BIRTHDAY\":\"15-10-1987\"},{\"NAME\":\"MERRY BLUE\",\"BIRTHDAY\":\"03-12-1983\",\"ID\":\"VN00000456\",\"GENDER\":\"Female\"},{\"GENDER\":\"Male\",\"ID\":\"VN00000789\",\"NAME\":\"BLACK BROWN\",\"BIRTHDAY\":\"09-07-1990\"}]"
};

//j is an object with one property (d) that is a JSON string that needs parsing
var o = parse(JSON.parse(j.d));
console.log(o);

2 of 3
2

You can try this example using jQuery:

https://jsfiddle.net/de02fpha/

var dump = {"d": "[{\"ID\":\"VN00000123\",\"NAME\":\"JOHN GREEN\",\"GENDER\":\"Male\",\"BIRTHDAY\":\"15-10-1987\"},{\"ID\":\"VN00000456\",\"NAME\":\"MERRY BLUE\",\"GENDER\":\"Female\",\"BIRTHDAY\":\"03-12-1983\"},{\"ID\":\"VN00000789\",\"NAME\":\"BLACK BROWN\",\"GENDER\":\"Male\",\"BIRTHDAY\":\"09-07-1990\"}]"};

var parse = function(json) {
  var columns = [];
  var data = [];
  $.each(json, function(index, row) {
    var element = [];
    for (var key in row) {
      if (columns.indexOf(key) == -1)	columns.push(key);
      element.push(row[key]);
    }
    data.push(element);
  });

  return {columns: columns, data: data};
};


var json = $.parseJSON(dump.d);
console.log(parse(json));
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>