Top Interview Questions & Answers | Learn Now

Json Interview Questions and Answers | Basic and Advanced Levels

Written by Bhavya Sri | Mar 15, 2018 7:24:33 AM

Q1. What is the full form of JSON?

Ans: JSON stands for JavaScript Object Notation.

Q2. What is the definition of JSON?
Ans: It is a text-based format and designed for the exchange of data between two different systems. It is lightweight data-interchange format as compare to XML. It uses JavaScript syntax. JSON data can be read and use by any programming language.

Q3. What is JSON used for?

Ans: JSON is used for communication between server side technologies and mobile app or website.

Q4. What is the file extension of JSON?

Ans: The file extension of JSON is .json.

Q5.  Who created the JSON?

Ans: Douglas Crockford

Q6.  Who is Father of JSON?

Ans: Douglas Crockford

Q7. Why It is so popular?

Ans:

  • 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

Q8. What is file extension of JSON?

Ans: json

Q9. What is the rule for writing JSON?

Ans:

  • JSON is the collection of key and value pair separated by the comma.
  • Key and value are separated by the colon (:).
  • Square brackets are used to store JSON array.
  • Curly brackets are used to hold JSON objects.

Q10. How many data types are there in JSON?

Ans: There are six types of data types in JSON -

  1. Number
  2. String
  3. Boolean
  4. Array
  5. Object
  6. Null

Q11. JSON vs. XML?

Ans:

  • XML requires XML parser to parse it. JSON is parsed with the help of JavaScript functions.
  • XML is heavy and verbose. JSON is short and lightweight.
  • File extension of XML data is .xml. File extension of JSON data is .json.
  • XML is document based. JSON is data based.
  • JSON is simple to read, write and understand. XML is less simple to read, write and understand.
  • Array is supported by JSON. Array is not supported by XML.
  • JSON stands for JavaScript Object Notation. XML stands for Extensible Markup Language.

Q12. What is MIME type for JSON data?

Ans: MIME type is application/json.

Q13. Which functions are used for encoding and decoding JSON in PHP?

Ans: For encoding, json_encode() function is used. This function takes PHP value like array as input and returns JSON representation of it. For decoding, json_decode() function is used. This function takes JSON string as input and returns associative array.

 

Q14. What is the use of JSON.stringify() function?

Ans: JSON.stringify() function is used to convert a JavaScript value(Object) into a JSON string.

Q15. What is MIME type for JSON data?

Ans: MIME type is application/json.

Q16. Which functions are used for encoding and decoding JSON in PHP?

Ans: For encoding, json_encode() function is used. This function takes PHP value like array as input and returns JSON representation of it. For decoding, json_decode() function is used. This function takes JSON string as input and returns associative array.

Q17. What is the use of JSON.stringify() function?

Ans: JSON.stringify() function is used to convert a JavaScript value(Object) into a JSON string.

Q18. What is the purpose of JSON.parse() function?

Ans: This function is used to convert JSON string into a JavaScript object.

Q19. What is JSON Parser?

Ans: JSON Parser is used to parse the JSON data into object to use its value. JSON can be parse by javaScript, jQuery and PHP.

Q20.What is JSON-RPC?

Ans: Remote Procedure call protocol with use of JSON. It is similar to XML-RPC only difference, It use JSON instead of XML.

Q21. What is JSON-RPC-Java?

Ans: JSON-RPC-Java is a Java implementation of the JSON-RPC protocol.

Q22. How to create json from php array?

Ans: $array = array('name'=>'PHP Tutorial','Description'=>'Web technology experts notes');
echo json_encode($array);

Q23.  How to get PHP array from json Object?

Ans: $object='{"name":"PHP Tutorial","Description":"Expert in web technology"}'; $array = json_decode($object);

Q24. How to parse JSON in JavaScript?

Ans: var json = '{"name":"PHP Tutorial","Description":"Web technology experts notes"}'
var obj = JSON.parse(json);
//alert(obj.name);

Q25.  How to create JSON Object from JavaScript?

Ans: var obj = {}; obj['name']='php-tutorial-php.blogspot.in'; //string obj['age'] = 32; // integer. obj['marks']= [80,70,60,50,60,80]; //array

Q26. How to parse JSON in jQuery?

Ans: var json = '{"name":"PHP Tutorial","Description":"Web technology experts notes"}'
obj = $.parseJSON(json);
//alert(obj.name);

Q27.  How to Validate json in php?

Ans: $json = '{"name":"PHP Tutorial","Description":"Web technology experts notes"}';
$obj = json_decode($json);
if(is_null($obj)) {
die('Invalid JSON');
}

Q28.  How to Validate json in javascript?

Ans: function isValidJson(jsonData) { try { JSON.parse(jsonData); return true; } catch (e) { return false; } } var json = '{"name":"PHP Tutorial","Description":"Web technology experts notes"}' isValidJson(json);

Q29.  How to Validate json in jQuery?

Ans: function isValidJson(jsonData) { try { $.parseJSON(jsonData); return true; } catch (e) { return false; } } var json = '{"name":"PHP Tutorial","Description":"Web technology experts notes"}' isValidJson(json);

Q30.  How to get JSON response in Ajax?

Ans:

$.ajax({

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