1.  

Who created the JSON?

Douglas Crockford is the Creator or Father of JSON.

2.  

Mention what is JSON?.

JSON is a simple data exchange format.  JSON means JavaScript Object Notation; it is language and   platform independent.

3.  

Why It is so popular?

  • It is light weight standard for exchange information
  • It is independent of language
  • It is independent of Hosting Server
  • Human Readable
  • Easy to Encode
  • Easy to Decode
  • Used in Mobile application
     
4.  

Where JSON is used?

It is used to transfer the information between two application. Information can also be exchanged between two different application which is running on different OR same server. It is used in Web Application, Mobile Application (IOS, Android, Iphone, window Phone)

5.  

What is file extension of JSON?

.json

6.  

How many languages, including in JSON?

Languages including in JSON are:

  • C
  • C++
  • C#
  • Java
  • JavaScript
  • Perl
  • Python
  • Php
     
7.  

What is the rule for JSON syntax rules? Explain with an example of JSON object?

The JSON syntax is a set of the JavaScript object notation syntax are:

  • The curly brackets hold objects
  • A data is in name and value pairs
  • The square bracket holds arrays
  • A data is separated by comma
     
8.  

Explain what is a JSON-RPC Parser?

JSON Parser: The JSON Parser is used for to parse JSON data into objects to use its value. It can be also parsed by the JavaScript, jQuery and PHP.


JSON RPC: The JSON RPC is a simple remote procedural call protocol similarly XML-RPC although it also uses the lightweight JSON format instead of XML.
 

9.  

Mention what are the data types supported by JSON?

Data types supported by JSON includes

  • Number
  • String
  • Boolean
  • Array
  • Object
  • Null
     
10.  

List out the uses of JSON?

Uses of JSON includes:

  • When writing application based on JavaScript it uses JSON, which includes browser extension and websites
  • JSON is used for transmitting and serializing structured data over network connection
  • JSON is mainly used to transfer data between server and web application
  • Web service and API’s use JSON format to provide public data
  • JSON can be used with modern programming language
11.  

Mention what are the drawbacks of JSON?

Drawbacks of json are:

 

Example:
  • It does not contain type definition
  • It lacks some sort of DTD
     
12.  

Explain what is JSON objects?

An object can be defined as an unordered set of name/value pairs.  An object in JSON starts with {left brace} and finish or ends with {right brace}.  Every name is followed by: (colon) and the name/value pairs are parted by, (comma).

13.  

Explain how to transform JSON text to a JavaScript object?

One of the common use of JSON is to collect JSON data from a webserver as a file or HTTP request, and convert the JSON data to a JavaScript, ant then it avails the data in a web page.

14.  

Explain how to work JSON with php?

The JSON is so easy with php. There is no installation needed to use these functions. They are part of the core php. The JSON with php use three php function is:

  • json_encode(): To get JSON dispaly of a value.
  • json_decode(): This function is used for Decodes a JSON string.
  • json_last_error(): This function is used for to get the last error occurred in the process.
     
Example:

For example:

$string=\'{
\"firstName\": \"Meraj\",
\"lastName\": \"Ansari\",
\"age\": 20,
\"address\": {
\"streetAddress\": \"Allahabad Road Faizabad \",
\"city\": \"Faizabad\",
\"state\": \"Uttar Pradesh\",
\"postalCode\": \"224001\"
},
\"phoneNumber\": [
{ \"type\": \"home\", \"number\": \"09839810502\" },
]
}\';
$decodeString = json_decode($string);
echo \'First Name - \'.$decode->{\"firstName\"};
echo \'Last Name - \'.$decode->{\"lastName\"};
echo \'Address - \'.$decode->{\"address\"}->{\"streetAddress\"};
 

15.  

Explain how to generate and send JSON Data at the Client Side?

Here is given following technique to generate and send data at the client side:

  • Create JSON JavaScript object
  • Use \*POST\” HTTP method in the open method of the XMLHttpRequest object
  • Pass JSON JavaScript object in the send method of XMLHttpRequest object
Example:

var carAsJSON = JSON.stringify(car);
var url = \”JSONExample?timeStamp=\” +new Date().getTime(); createXMLHttpRequest();
xmlHttp.open(\”POST\”, url, true);
xmlHttp.onreadystatechange = handleStateChange;
xmlHttp.setRequestHeader(\”Content-Type\”, \” application/x-www-from-urlencoded\”);
xmlHttp.send(carAsJSON);

16.  

Mention how to parse JSON in jQuery?

Example:

var json = '{"name":"J2EE Tutorial","Description":"www.J2eebrain.com"}'
    obj = $.parseJSON(json);
    //alert(obj.name);

17.  

Explain how to Validate JSON in PHP?

Example:

$json = '{"name":"J2EE Tutorial","Description":" www.J2eebrain.com "}';
$obj = json_decode($json);
if(is_null($obj)) {
 die('Invalid JSON');
}

18.  

Explain how to get a JSON response in Ajax?

Example:

$.ajax({
  dataType: "json",
  url: '/ajax/url',
  data: 'name=J2EE-tutorial-J2EE',
  success: function(data){
  //data
  }
});
 

19.  

What are similarities between XML in JSON?

Because:

  • The JSON and XML both are structural (values within values)
  • The JSON and XML both are “self describing” (human readable)
  • JSON and the XML both are can be fetched with an XMLHttpRequest
  • The JSON and XML both are can be parsed and used by more programming language
     
20.  

What are difference between XML and JSON?

Because:

  • The JSON does not use end tag
  • The JSON is shorter
  • The JSON is quicker to read and write
  • The JSON can use arrays

The biggest difference is:

XML has to be parsed by an XML parser, the JSON also can be parsed by a standard JavaScript function.