Follow Me:

Wednesday, 13 May 2015

What is JSON?

JavaScript Object Notation (JSON) is a lightweight data-interchange format inspired by the object literals of JavaScript. 

JSON values can consist of:

  •   objects (collections of name-value pairs)
  •   arrays (ordered lists of values)
  •   strings (in double quotes)
  •   numbers
  •   true, false, or null

JSON is language independent.

JSON with PHP?

   After PHP Version 5.2.0, JSON extension is decodes and encodes functionalities as default.

  • Json_encode     - returns the JSON representation of values
  • Json_decode     - Decodes the JSON String
  • Json_last_error - Returns the last error occured.

JSON Syntax and Rules?

   JSON syntax is derived from JavaScript object notation syntax:

  • Data is in name/value pairs
  • Data is separated by commas
  • Curly braces hold objects
  • Square brackets hold arrays

JSON Example

    This example is simple phone number validation and once phone number has validated , it will be sent this php page, there we are using the json format related encode data.

Html Page:
<title>JSON Example in Php</title>
<script src="js/jquery-1.11.0.min.js"></script>
<h1>Json Basic Example</h1>
<form name="phone-form" method="post" onsubmit="return validation();">
 <input type="text" name="phone" id="phone" value="" >
 <input type="submit" value="submit" >
<div id="outputDisplay"></div>

Javascript Function

function validation(value){ 
 //Phone Number Validations
 var phone   = $('#phone').val();
 var specialDigitPattern  = /[~`!@#\$%\^&\*()\-_\+=|\\{}\[\]:;"'<>,\?\/\.0123456789]/;
 //var mailvalidateregex  = /^([a-zA-Z0-9_.+-])+\@(([a-zA-Z0-9-])+\.)+([a-zA-Z0-9]{2,4})+$/;  email validation
 if(phone == ""){
  alert("Please enter the phone ");
  return false;
 }else if(isNaN(phone)){
  alert('Please Enter Valid Phone Number');
  return false;
 var postdata  = 'phone='+phone;
 var url   = 'testphone.php?phone='+phone;
  type  : "POST",
  url   : url, 
  data  : postdata,
  dataType : "json",
  success  : phonestatus_check,
 return false;

function phonestatus_check(response){
 if(response.status == 1){
  return false;

Php Page:

  $phonenumber = $_POST['phone'];
  $responsearray = array();$responsestatus = '1';
  if($responsestatus == 1){
      $responsearray = array('status' => 1,'message'=> 'Thanks for submitting the Phone Number');
   $responsearray = array('status' => 0,'message'=> 'failure');
  echo json_encode($responsearray);
  /* $json = json_encode($responsearray);
   exit("{$_GET['jsoncallback']}($json)"); */

Categories: ,


  1. Thanks for sharing this informative content that guided me to know the details about the training offered in different technology.
    digital marketing course in chennai | digital marketing training in Chennai

    1. I have read your blog its very attractive and impressive. I like it your blog.

      JavaScript Training in Chennai

      Angularjs Training in Chennai

    2. JavaScript is the language future. The new JavaScript Version (Ecmascript 6) has been relaeased.

      JavaScript Online Training

      Javascript Online Training

  2. crystal clear post, you shared everything with screenshot, so it really helpful to understand the concept as well.
    PHP Training in Chennai|PHP Course in Chennai


  3. Thanks for posting this useful content, Good to know about new things here, Let me share this, . Hadoop training in pune

  4. Thanks for your great information. Sign up and Register Your Events Today!!!!!!!
    College Events Registration

  5. Very Nice Blog I like the way you explained these things. I’ve been looking for ways to improve my website and overall rankings.I hope your future article will help me further.Take SEO Training in Chennai to mould yourself.

  6. Nice blog. Thank you for sharing. The information you shared is very effective for learners I have got some important suggestions from it. erp software in chennai.

  7. Thank you for this valuable information. Get your business to the next level in simple steps. We provides lowest price of erp Software for our clients cloud erp in Chennai

  8. Great information. I have got some important suggestions from it.
    Best institute chennai

  9. Those guidelines additionally worked to become a good way to recognize that other people online have the identical fervor like mine to grasp great deal more around this condition.

    Java Training in Bangalore|