JSON Parse() Method

You are Here:

Why JSON.parse()

When receiving a string from the web server, you have to convert that string to an object to process the received data. Thus JSON.parse() comes in action.

Note: String is the only data type to exchange data between a browser and a web-server.

Receiving Data From Server-Side to Client-Side

The web-server will send a string to the client-side. It's your choice whether or not to convert that string to an object. To convert a string to an object, use JSON.parse().

Note: jQuery will not convert the received string to an object by itself.

Example

HTML Editor
<!DOCTYPE html> <html lang="en-US"> <head> <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.4.1/jquery.min.js"></script> </head> <body> <h1>JSON.parse()</h1> <p id="point"></p> <button onclick="myFunction()">Receive from Server</button> <script> var x = document.getElementById("point"); var data = {}; function myFunction(){ $.post("/json-receive.php",{ // send no data },function(serverData){ data = JSON.parse(serverData) x.innerHTML = data[0].name; }); } </script> </body> </html>

Syntax

JSON.parse(string)

Reminder

Hi Developers, we almost covered 100% of JSON Tutorials with examples for quick and easy learning.

We are working to cover every Single Concept in JSON.

Please do google search for:

Join Our Channel

Join our telegram channel to get an instant update on depreciation and new features on HTML, CSS, JavaScript, jQuery, Node.js, PHP and Python.

This channel is primarily useful for Full Stack Web Developer.

Share this Page

Meet the Author