JSON Interview Questions

Level: Freshers

Q 1 - Who created the JSON?

Douglas Crockford is the Creator or Father of JSON.

Q 2 - Mention what is JSON?.

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

Q 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
     

Q 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)

Q 5 - What is file extension of JSON?

.json

Q 6 - How many languages, including in JSON?

Languages including in JSON are:
  • C
  • C++
  • C#
  • Java
  • JavaScript
  • Perl
  • Python
  • Php
     

Q 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
     

Q 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.
 

Q 9 - Mention what are the data types supported by JSON?

Data types supported by JSON includes
  • Number
  • String
  • Boolean
  • Array
  • Object
  • Null
     

Q 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

Q 11 - Mention what are the drawbacks of JSON?

Drawbacks of json are:  
Example: <ul> <li>It does not contain type definition</li> <li>It lacks some sort of DTD<br /> &nbsp;</li> </ul>

Q 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).

Q 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.

Q 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=\&#39;{<br /> \&quot;firstName\&quot;: \&quot;Meraj\&quot;,<br /> \&quot;lastName\&quot;: \&quot;Ansari\&quot;,<br /> \&quot;age\&quot;: 20,<br /> \&quot;address\&quot;: {<br /> \&quot;streetAddress\&quot;: \&quot;Allahabad Road Faizabad \&quot;,<br /> \&quot;city\&quot;: \&quot;Faizabad\&quot;,<br /> \&quot;state\&quot;: \&quot;Uttar Pradesh\&quot;,<br /> \&quot;postalCode\&quot;: \&quot;224001\&quot;<br /> },<br /> \&quot;phoneNumber\&quot;: [<br /> { \&quot;type\&quot;: \&quot;home\&quot;, \&quot;number\&quot;: \&quot;09839810502\&quot; },<br /> ]<br /> }\&#39;;<br /> $decodeString = json_decode($string);<br /> echo \&#39;First Name - \&#39;.$decode-&gt;{\&quot;firstName\&quot;};<br /> echo \&#39;Last Name - \&#39;.$decode-&gt;{\&quot;lastName\&quot;};<br /> echo \&#39;Address - \&#39;.$decode-&gt;{\&quot;address\&quot;}-&gt;{\&quot;streetAddress\&quot;};<br /> &nbsp;

Q 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);<br /> var url = \&rdquo;JSONExample?timeStamp=\&rdquo; +new Date().getTime(); createXMLHttpRequest();<br /> xmlHttp.open(\&rdquo;POST\&rdquo;, url, true);<br /> xmlHttp.onreadystatechange = handleStateChange;<br /> xmlHttp.setRequestHeader(\&rdquo;Content-Type\&rdquo;, \&rdquo; application/x-www-from-urlencoded\&rdquo;);<br /> xmlHttp.send(carAsJSON);

Q 16 - Mention how to parse JSON in jQuery?

Example: var json = &#39;{&quot;name&quot;:&quot;J2EE Tutorial&quot;,&quot;Description&quot;:&quot;www.J2eebrain.com&quot;}&#39;<br /> &nbsp; &nbsp; obj = $.parseJSON(json);<br /> &nbsp; &nbsp; //alert(obj.name);

Q 17 - Explain how to Validate JSON in PHP?

Example: $json = &#39;{&quot;name&quot;:&quot;J2EE Tutorial&quot;,&quot;Description&quot;:&quot; www.J2eebrain.com &quot;}&#39;;<br /> $obj = json_decode($json);<br /> if(is_null($obj)) {<br /> &nbsp;die(&#39;Invalid JSON&#39;);<br /> }

Q 18 - Explain how to get a JSON response in Ajax?

Example: $.ajax({<br /> &nbsp; dataType: &quot;json&quot;,<br /> &nbsp; url: &#39;/ajax/url&#39;,<br /> &nbsp; data: &#39;name=J2EE-tutorial-J2EE&#39;,<br /> &nbsp; success: function(data){<br /> &nbsp; //data<br /> &nbsp; }<br /> });<br /> &nbsp;

Q 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
     

Q 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.