Prepare Interview

Exams Attended

Mock Exams

Make Homepage

Bookmark this page

Subscribe Email Address

JSON Interview Questions and Answers

Intermediate / 1 to 5 years experienced level questions & answers

Ques 1. Why use JSON over XML?

Lighter and faster than XML as on-the-wire data format
JSON objects are typed while XML data is typeless
> JSON types: string, number, array, boolean,
> XML data are all string
Native data form for JavaScript code
> Data is readily accessible as JSON objects in your JavaScript
code vs. XML data needed to be parsed and assigned to variables through tedious DOM APIs
> Retrieving values is as easy as reading from an object property in your JavaScript code

Is it helpful? Add Comment View Comments
 

Ques 2. Explain JSON Structures.

A collection of name/value pairs
> In various languages, this is realized as an object, record, struct, dictionary, hash table, keyed list, or associative array
An ordered list of values
> In most languages, this is realized as an array, vector, list, or sequence
These are universal data structures supported
A JSON object is an unordered set of name/value pairs
A 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)

Is it helpful? Add Comment View Comments
 

Ques 3. Compare JSON with JavaScript.

JSON is a subset of the object literal notation of JavaScript
> JSON can be used in the JavaScript language with no muss or fuss
Example: JSON Object
var myJSONObject = {"bindings": [ {"ircEvent": "PRIVMSG", "method": "newURI", "regex": "^http://.*"},
{"ircEvent": "PRIVMSG", "method": "deleteURI", "regex": "^delete.*"},
{"ircEvent": "PRIVMSG", "method": "randomURI", "regex": "^random.*"}
]
};
In this example, a JSON JavaScript object is created
containing a single member "bindings", which contains
an array containing three objects, each containing
"ircEvent", "method", and "regex" members
Members can be retrieved using dot or subscript
operators myJSONObject.bindings[0].method // "newURI"
Text to Object Conversion in
JavaScript code
var myObject = eval('(' + myJSONtext + ')');
To convert a JSON text into an JSON object, use
the eval() function > eval() invokes the JavaScript compiler
> Since JSON is a proper subset of JavaScript, the compiler will
correctly parse the text and produce an object structure

Is it helpful? Add Comment View Comments
 

Ques 4. How to Generate or Send JSON Data at the Server Side?

Create JSON Java object
Add name and value pairs using put method
Convert it to String type using toString method and send it to the client with content-type as "text/xml" or "text/plain"
myString = new JSONObject().put("JSON", "Hello, World!").toString();
// myString is {"JSON": "Hello, World"}

Is it helpful? Add Comment View Comments
 

Ques 5. How to receive JSON Data at the Client Side?

JSON data is received as a string
Calling eval() will generate JSON object in JavaScript code
var JSONdata = eval(req.responseText);
Once you have JSON object, you can use . notation to access its properties
var name = JSONdata.name;
var address = JSONdata.addresses[3];
var streetname = JSONdata.addresses[3].street;

Is it helpful? Add Comment View Comments
 

Ques 6. How to Generate/Send JSON 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
var carAsJSON = JSON.stringify(car);
var url = "JSONExample?timeStamp=" + new Date().getTime(); createXMLHttpRequest();
xmlHttp.open("POST", url, true);
xmlHttp.onreadystatechange = handleStateChange;
xmlHttp.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
xmlHttp.send(carAsJSON);

Is it helpful? Add Comment View Comments
 

Ques 7. How to receive JSON Data at the Server Side?

Read the JSON data as a String type
Create JSONObject Java object from the string String json = readJSONStringFromRequestBody(request);
//Use the JSON-Java binding library to create a JSON object in Java JSONObject jsonObject = null;
try {
jsonObject = new JSONObject(json);
}
catch(ParseException pe) {
}

Is it helpful? Add Comment View Comments
 

Most helpful rated by users:

Related differences

JSON vs XML

Related interview subjects

Apache Kafka interview questions and answers - Total 38 questions
Language in C interview questions and answers - Total 80 questions
ANT interview questions and answers - Total 10 questions
Nature interview questions and answers - Total 20 questions
Ruby On Rails interview questions and answers - Total 74 questions
Business Analyst interview questions and answers - Total 40 questions
HTML interview questions and answers - Total 27 questions
Hadoop interview questions and answers - Total 40 questions
iOS interview questions and answers - Total 52 questions
HR Questions interview questions and answers - Total 49 questions
C++ interview questions and answers - Total 142 questions
Cryptography interview questions and answers - Total 40 questions
JSON interview questions and answers - Total 16 questions
CSS interview questions and answers - Total 74 questions
XML interview questions and answers - Total 25 questions
Ethical Hacking interview questions and answers - Total 40 questions
Android interview questions and answers - Total 14 questions
ChatGPT interview questions and answers - Total 20 questions
Data Structures interview questions and answers - Total 49 questions
Zend Framework interview questions and answers - Total 24 questions
Fashion Designer interview questions and answers - Total 20 questions
REST API interview questions and answers - Total 52 questions
Unix interview questions and answers - Total 105 questions
SDLC interview questions and answers - Total 75 questions
©2023 WithoutBook