StuffArrow is under maintenance. These are the demo deals and offers you are seeing here. We will come up with fresh and live deals and offers soon. Thanks for your patience. Keep visit our site for updates

JSON Interview Questions and Answers

Here we will keep publish JSON interview questions and Answers which can be asked in interview. Below we are publishing some JSON interview questions and keep on posting new json questions.

  • What is JSON?
  • Which is better XML or JSON and why?
  • How to write JSON object?
  • How to save the json file? Or what is the file extension of JSON?
  • Which datatypes JSON supports?
  • Is it possible to convert the text into javascript object?
  • What is the purpose of stringyfy function in JSON?
  • What is the MIME type of JSON file?
  • What is JSON parser?

 

What is JSON?

JSON is JavaScript Object Notation. It is very commonly used now for data transfer. It is platform independent and language independent also.

 

Which is better XML or JSON and why?

Obviously JSON is better than XML due to following reason.

  • There is un-necessary code in xml, which is not in JSON.
  • Parsing the xml is slow and take longer time than manipulating JSON (JSON is lighter).
  • JSON is far better in case of understanding

XML

<employees>
    <employee>
        <firstName>Steve</firstName> <lastName>Bath</lastName>
    </employee>
    <employee>
        <firstName>Henry</firstName> <lastName>Holt</lastName>
    </employee>
    <employee>
        <firstName>Smith</firstName> <lastName>Joseph</lastName>
    </employee>
</employees>

 

 

JSON

{"employees":[
    { "firstName":"Steve", "lastName":"Bath" },
    { "firstName":"Henry", "lastName":"Holt" },
    { "firstName":"Smith", "lastName":"Joseph" }
]}

 

 

In this example of employee object, you can see the difference between the XML and JSON. Lot of extra code need to be written in case of xml.

 

How to write JSON object?

JSON object is written in key:value pair followed by comma (,). Object will be written in curly brackets.

e.g. In above example, employee object has first name

“firstName”:”Steve”

 

How to save the json file? Or what is the file extension of JSON?

JSON file is saved as filename.json

 

Which datatypes JSON supports?

Following data types supported by JSON:

Null

Object

Number

String

Boolean

Array

 

Is it possible to convert the text into javascript object?

Yes, using eval() we can convert the text into javascript object.

<!DOCTYPE html>
<html>
<body>

<h2>JSON Eval Example</h2>

<p id="demo"></p>

<script>
var data = '{"students":[' +
'{"firstName":"Allen","lastName":"Lee" },' +
'{"firstName":"Steve","lastName":"joseph" },' +
'{"firstName":"stuff","lastName":"Arrow" }]}';

var obj = eval ("(" + data + ")");

document.getElementById("demo").innerHTML =
obj.students[2].firstName + " " + obj.students[2].lastName;
</script>

</body>
</html>

Its output  is  “stuffArrow”.

 

What is the purpose of stringyfy function in JSON?

JSON.stringyfy() is used to convert the javascript object into string.

 

What is the MIME type of JSON file?

The MIME type of JSON is “application/json”.

 

What is JSON parser?

JSON parser is used to convert the JSON data into object.

 

 

Newsletter

%d bloggers like this: