Professional Documents
Culture Documents
JSON: JavaScript Object Notation.
JSON is syntax for storing and exchanging data.
JSON is text, written with JavaScript object notation
JSON is a lightweight data-interchange format
JSON is "self-describing" and easy to understand
JSON is language independent.
Syntax:
Data is in name/value pairs
Data is separated by commas
Curly braces hold objects
Example for Java Script Object: (Here employee is a java script object)
Receiving Data: (JSON file convert into Java Script object file)
HTTP Request:
You can request JSON from the server by using an AJAX request
The response from the server is written in JSON format, you can parse the string into a
JavaScript object.
<!DOCTYPE html>
<html>
<body>
<p id="demo"></p>
<script>
var xmlhttp = new XMLHttpRequest();
xmlhttp.onreadystatechange = function()
{
if (this.readyState == 4 && this.status == 200)
{
var myObj = JSON.parse(this.responseText);
document.getElementById("demo").innerHTML = myObj.name;
}
};
xmlhttp.open("GET", "json_demo.txt", true);
xmlhttp.send();
</script>
</body>
</html>
Output:
John