Top 16 Json Interview Question and Answer

Q.what is JSON ?

A.JSON stands for JavaScript Object Notation.Json is used to data transfer between server and web application.It does not have end tag and reserved word like XML.Json Internet Media type is "application/json".

Q.Who is Father of JSON?

A.Douglas Crockford is Father of JSON.

Q.Why would we use JSON Over XML?

A. We should use JSON Over XML because of following reason.

  • It is faster and lighter than XML.
  • JSON objects are typed while XML data is typeless.
  • XML items must be wrapped in open and close tags whereas JSON you just name the tag once.
  • Fetching values is as simple as reading from an object property.

Q.Which function is used to convert a JSON text into an object?

A.JSON.parse() method is used to parses a string as JSON.
    JSON.parse(jsonString);

Q.what is the MIME type of JSON?

A."application/json" is MIME type of JSON.

Q.what is JSONP?

A.JSONP as in "JSON with Padding".JSONP is a method commonly used to bypass the cross-domain policies in web browsers.

Q.Define the use of JSON.stringify ?

A.JSON.stringify() method converts a JavaScript value to a JSON string.
    JSON.stringify(value [, replacer] [, space]);

<script type="text/javascript">
var usercontact = new Object();
usercontact.firstname = "Manish";
usercontact.surname = "Mishra";
var jsonText = JSON.stringify(usercontact);
document.write(jsonText);
// Output: 
// {"firstname":"Manish","surname":"Mishra"}
</script>

Q.what are the drawbacks of JSON?

A.No namespace support, hence poor extensibility.
    Less development tools support as XML.
    We can't use comments in JSON.

Q.Explain about JSON Structures.?

A.JSON object is an unordered set of name/value pairs.
    JSON object begins with left brace ({) and ends with right brace (}).
    Each name is followed by colon (:) and the name/value pairs are separated by comma(,).
    Example:
{ "language": "Json", "edition": "third", }

Q.Explain what is the data type supported by JSON?

A.Following data type are supported by JSON.
    Number
    Boolean
    String
    Null
    Object
    Array

Q.How to parse JSON in JQuery?

A.To parse JSON in JQuery, we will use "$.parseJSON(json);" function.
    Example:
var json = '{"name": "tutsway", "Description":"Learn Json Interview Question and Answer"}' jsonobj = $.parseJSON(json); //alert(jsonobj.name);

Q.How to Validate JSON in JQuery ?

A.To Validate JSON in JQuery, we will use "$.parseJSON();" function.
    Example:
function checkJson(jsonData) { try { $.parseJSON(jsonData); return true; } catch (e) { return false; } } var json = '{"name": "tutsway", "Description":"Learn Json Interview Question and Answer"}' checkJson(json);

Q.How to Validate JSON in PHP ?

A.To Validate JSON in PHP, we will use "$json_decode();" function.
    Example:
$json = '{"name": "tutsway", "Description":"Learn Json Interview Question and Answer"}'; $obj = json_decode($json); if(is_null($obj)) {  die('JSON is Invalid.'); }

Q.How to Validate JSON in JavaScript ?

A.To Validate JSON in JavaScript, we will use "JSON.parse();" function.
    Example:
function checkJson(jsonData) { try { JSON.parse(jsonData); return true; } catch (e) { return false; } } var json = '{"name": "tutsway", "Description":"Learn Json Interview Question and Answer"}' checkJson(json);

Q.How to get JSON response in Ajax?

A.To get JSON response in Ajax, we will use following code.
    Example:
$.ajax({ dataType: "json", url: '/ajax-url', data: 'name=php-tutorial-php', success: function(data){ //your code. } });

Q.What are online tool for Validate JSON data?

A.http://jsonlint.com