JSON Interview Questions and Answers

Mention how to parse JSON in jQuery?

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

Explain how to Validate JSON in PHP?

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

Mention how to Validate JSON in JavaScript?

function isValidJson(jsonData) {
    try {
        return true;
    } catch (e) {
        return false;
var json = '{"name":"J2EE Tutorial","Description":" www.J2eebrain.com "}'

How to convert the JSON object to a JSON string in the jQuery?

var json = '{"name":"J2EE Tutorial","Description":" www.J2eebrain.com "}'

Explain how to get a JSON response in Ajax?

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

Explain why one use JSON use JSON over XML?

  • JSON is faster and lighter than XML as the data on the wire format
  • The XML data is typeless while JSON objects are typed
  • The JSON types: Number, Boolean, Array, String
  • The data are all strings
  • The data is readily available as JSON object is in your JavaScript
  • Fetching values is simple as reading from an object property in your JavaScript code

Mention which function is used for encoding JSON?

To encoding JSON in PHP, json_encode() function is used. Which function returns the JSON representation of a value on success or false on failure.

Explain which technique to convert a string into a JSON Array?

To convert a string into a JSON array, you want to make a JSONObject object for each of your objects, and add those to your JSON array.

What is use of JSON?

Uses of JSON include

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

What is JSONP?

The JSONP stands for JSON with padding. JSONP method is used to bypass the cross-domain policies in web browsers. In other words, we can say that, JSONP is the simplest way to deal with browser restrictions when sending JSON responses from different domains from the client.

What is the difference between JSONP and JSON?

  • JSONP: The JSONP is a methodology for using that format with cross domain Ajax requests while not being affected by the same origin policy issue.
  • JSON: The JSON is a simple data format used for communication medium between other systems

What are similarities between XML in JSON?


  • 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

 What are difference between XML and JSON?


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