What is JSON?

JSON with Ajax

JSON or JavaScript Object Notation is nothing but a text-based human-readable data storing and interchange. Douglas Crockford originally specified the this format.
The media for this is application/json and the extension is .json.
This is an easier-to-use alternative of XML.

The below example shown an student object with an array of 3 records:

    {"Name":"Tim", "Age":"25"},
    {"Name":"John", "Age":"30"},
    {"Name":"Jane", "Age":"45"}

Below example you can loop through:

<!DOCTYPE html>
<p id="demo"></p>
  var str = '';
  var text = {"students":[{"Name":"Tim", "Age":"25"},{"Name":"John", "Age":"30"},{"Name":"Jane", "Age":"45"}]};
  var obj = text.students;
  for ( var i in obj) {
    str +=obj[i].Name+ ":" + obj[i].Age+"<br>";
  document.getElementById("demo").innerHTML = str;

So why JSON?

For AJAX JSON, is faster and easier.
JSON is quicker for reading and writing.

Leave a Reply

Your email address will not be published. Required fields are marked *