JSON Multiple choice Questions and Answers |
JSON Objective type Questions and Answers List
1. JSON name/value pair is written asA. name’ : ‘value’
B. name = ‘value’
C. name = “value”
D. “name” : “value”
Ans: D
2. JSON strings have to be in
A. single quote
B. double quote
C. single quote or double quote
Ans:B
3. In the below notation, Employee is of type { “Employee”: [ “Amy”, “Bob”, “John” ] }
A. Not a valid JSON string
B. Array
C. Class
D. Object
Ans:B
4. Which of the following is not a JSON type?
A. Object
B. date
C. Array
D. string
Ans:B
5. Which of these is correct about the JSON standard?
A. It is an open standard
B. It is privately developed
C. It requires a license to use
Ans:A
6. What is the file extension of JSON?
A. .jn
B. .js
C. .jsn
D. .json
Ans:D
7. In modern websites what is the common usage for JSON?
A. To store information remotely.
B. To send and receive bits of data.
C. To store information locally.
Ans:B
8. Which of the following code will return a valid JSON object?
A. JSON.parse(‘({“FirstName”: “John”, “LastName”:”Doe”})’);
B. JSON.parse(“{‘FirstName’: ‘John’, ‘LastName’:’Doe’}”);
C. JSON.parse(“({‘FirstName’: ‘John’, ‘LastName’:’Doe’})”);
D. JSON.parse(‘{“FirstName”: “John”, “LastName”:”Doe”}’);
Ans:D
9. Which of these is proper a JSON array?
A. { “letters” : [ “a”, “b”, “c”; ] }
B. { ‘letters’ : {“a”, “b”, “c” } }
C. { “letters” : [ a, b, c ] }
D. { “letters” : [ “a”, “b”, “c” ] }
Ans:D
10. In the below notation, Employee is of type { “Employee”: { “Name”: “Amy”, “Age”: 25 } }
A. Object
B. Array
C. Class
D. Not a valid JSON string
Ans:A
11. Which answer represents the following order of TYPES? Object, String, Boolean, Number
A. “{ }”, “a string”, “false”, “0”
B. [ ], 0, “true”, “0”
C. { }, “0”, false, 0
D. { }, hello, “false”, “0”
Ans:C
12. In this example, what is the TYPE of employee?
{ “employee” : { “type” : “Director”, “functions” : [‘sales’, ‘marketing’] } }
A. String
B. Director
C. type
D. Object
Ans:D
13. Given this JSON example:
{ “Employee”: { “Name”: “Amy”, “Age”: 25 } }; What is the type of Employee.Age ?
A. Number
B. Object
C. Array
D. String
Ans:A
14. Which of these is a benefit JSON has over XML?
A. JSON is more forgiving of poor formatting
B. JSON has less markup requirements and therefore is lighter than XML
C. JSON can be written poorly and still be parsed
D. JSON does not need to be stored in a file to be sent remotely
Ans:B
15. Which statement about the replacer parameter in JSON.stringify() is true?
A. If null or omitted, all properties of the object are included in the resulting JSON string
B. If a function, transforms values and properties encountered while stringifying
C. All three statements are true
D. If an array, specifies the names of the properties in the object to include in the resulting JSON string
Ans:C
16. What does JSON stand for?
A. JavaScript Object Nomenclature
B. JavaScript Objective Notation
C. JavaScript Object Notation
D. JavaScript Orientated Nomenclature
Ans:C
17. JSON elements are separated by
A. semi-colon
B. line break
C. comma
D. white space
Ans:C
18. What keywords are reserved in JSON and cannot be used as keys?
A. Value
B. Object
C. There are none.
D. Key
Ans:C
19. Which of the following is a valid JSON string?
A. { “meals” : { “breakfast” , “lunch” , “dinner” } }
B. { “meals” : [ “breakfast” , “lunch” , “dinner” ] }
C. [ “meals” : { “breakfast” , “lunch” , “dinner” } ]
D. [ {“meals” : { “breakfast” , “lunch” , “dinner” } } ]
Ans:B
20. Which of the following code will throw an error?
A. JSON.parse(null);
B. JSON.parse(‘{}’);
C. JSON.parse(undefined);
D. JSON.parse(‘[]’);
Ans: C
21. Which statement about the toJSON method is true?
A. It customizes JSON stringification behavior
B. It allows an object to determine its own JSON representation
C. All three statements are true
D. It is internally called by JSON.stringify()
Ans: C
22. Which of these data interchange formats has seen a decline in usage in favor of JSON?
A. ASCII
B. Plain-text
C. SQL
D. XML
Ans: D
23. True or false? A disadvantage of JSON is that it requires the use of JavaScript.
A. False, JSON is language independent.
B. False, JavaScript must be available although it is not necessary to use.
C. True, though all browsers have JavaScript enabled.
D. True, though JavaScript is readily available in today’s browsers.
Ans: A
24. Which is true about JSON namespacing?
A. JSON namespaces can be accessed immediately after receiving data.
B. JSON namespaces can be accessed after parsing data.
C. JSON doesn’t have namespaces. Though every object is inherently a namespace.
Ans:C
25. What kind of format is JSON, and what does the acronym mean?
A. A lightweight data-encoding framework. Java Omnipresent Notation.
B. A lightweight data-interchange format. JavaScript Object Notation.
C. A lightweight data-interchange format. Java Objective Notion.
D. A lightweight database framework. JavaScript Object Notation.
Ans: B
26. Can you use a double quote inside a JSON string?
A. Yes, if you use the ascii code.
B. Yes, you can use it without any special treatment
C. Yes, if it is escaped like ( \” )
D. No, you should use single quotes
Ans:C
27. In this example, what is the TYPE of employee.functions?
{ “employee” : { “type” : “Director”, “functions” : [‘sales’, ‘marketing’] } }
A. String
B. Object
C. Array
D. Sales, Marketing
Ans:C
28. Which statement about the reviver parameter in JSON.parse() is true?
A. All three statements are true
B. Used to reform generic objects into instances of pseudo-classes
C. A function that will be called for every key and value at every level of the final result
D. Each value will be replaced by the result of the reviver function
Ans: A
29. What function will convert a JavaScript object to a JSON string?
A. JSON.text()
B. JSON.serialize()
C. JSON.toString()
D. JSON.stringify()
Ans: D
30. In this example, what would the VALUE of employee.functions[1] be?
{ “employee” : { “type” : “Director”, “functions” : [‘sales’, ‘marketing’] } }
A. null
B. undefined
C. marketing
D. sales
Ans: C
31. What is the MIME type of JSON?
A. application/x-json
B. text/json
C. application/json
D. application/javascript
Ans: C
32. In this example, what is the VALUE of employee.type?
{ “employee” : { “type” : “Director”, “functions” : [‘sales’, ‘marketing’] } }
A. String
B. Object
C. Director
Ans: C
33. In this example, what would the TYPE of employee.hireDate be?
{ “employee” : { “type” : “Director”, “functions” : [‘sales’, ‘marketing’], “hireDate” : “March 8, 2011” } }
A. March 8, 2011
B. String
C. Date
D. Number
Ans: B
34. What is JSONP meant to mitigate?
A. Size constraints of JSON
B. Cross-domain communication
C. Future proofing JSON as JavaScript changes.
Ans: B
35. True or false? The order of elements in JSON arrays is always preserved.
A. False
B. True
Ans: B
36. Which of these is supported as a JSON Value type?
A. Infiniti
B. Null
C. Undefined
D. NaN
Ans: B
37. When coding a string object in JSON, what must separate the string and the value?
A. A space
B. A semicolon
C. A comma
D. A colon
Ans: D
38. Does JSON support Unicode characters?
A. No, JSON has no support for any kind of character encoding.
B. No, JSON only has support for UTF-8 characters.
C. Yes, JSON has support for Unicode characters. Allowing for almost any information in any human language
D. Yes, only when stored as the key in a ( key : value ) pair.
Ans: C
39. What is the value of obj in the following code?
var obj = JSON.parse(‘{“fruit”: “Apple”}’, function(k, v) { if (v == “Apple”) return “Orange” else return v; });
A. { “fruit” : “Apple”}
B. { “fruit” : “Orange”}
C. {“Orange”}
D. {“Apple”}
Ans: B
40. In what situation would you want to use XML over JSON?
A. When JSON is not offered.
B. When you need to use tags to structure your content.
C. You need message validation or you’re using XSLT.
D. Never, JSON is worlds better.
Ans: C
41. What is a JSONStringer used for?
A. It is used to quickly create JSON text.
B. It quickly converts JSON to Java strings.
C. It is used to create number strings in JSON.
D. It is used to create JSON ordered pairs.
Ans: A
42. Which of the following control characters cannot be used when writing a JSON string without escaping?
A. ; or :
B. “ or \
C. < or >
D. / or {
Ans: B
43. What is the value of json in the following code?
var days = {}; days[‘Monday’] = true; days[‘Wednesday’] = true; days[‘Sunday’] = false; var json = JSON.stringify({x: days});
A. {“day”:{“Monday”:”true”,”Wednesday”:”true”,”Sunday”:”false”}}
B. {“x”:{“Monday”:true,”Wednesday”:true,”Sunday”:false}}
C. {“day”:{“Monday”:true,”Wednesday”:true,”Sunday”:false}}
D. {“x”:[“Monday”:true,”Wednesday”:true,”Sunday”:false]}
Ans: B
44. How does JSON being “lightweight” translate into a benefit for the site visitors?
A. Faster transfer times over the internet
B. Parsing JSON is noticeably faster than parsing XML
C. Web apps have a smaller footprint
Ans: A
45. What error does JSON.parse() throw when the string to parse is not valid JSON?
A. ReferenceError
B. EvalError
C. SyntaxError
D. TypeError
Ans: C
46. What two structures is JSON built on?
A. A collection of name/value pairs, and an ordered list of values, or array.
B. A collection of object/item pairs, and an ordered list of pairs, or array.
C. A collection of name/value objects, and an ordered list of objects, or array.
D. A collection of native-value pairs, and an ordered list of arrays, or values.
Ans: A
47. Which of the following is not a valid way to parse JSON string?
A. JSON.eval()
B. JSON.parse()
C. jQuery.parseJSON()
D. eval()
Ans: A
48. Does whitespace matter in JSON?
A. No, it will be stripped out.
B. Yes, only within strings.
C. Yes, only outside of strings.
D. Yes, both inside and outside of strings
Ans: B
49. What is the value of json in the following code?
var cars = []; cars[0] = ‘Ford’; cars[1] = ‘Toyota’; cars[2] = ‘BMW’; var json = JSON.stringify({x: cars});
A. {“x”:[‘Ford’,’Toyota’,’BMW’]}
B. {“x”:{“Ford”,”Toyota”,”BMW”}}
C. {“x”:[“Ford”,”Toyota”,”BMW”]}
D. {“cars”:[“Ford”,”Toyota”,”BMW”]}
Ans: C
50. What is the value of json in the following code?
var obj = { fruit: ‘apple’, toJSON: function () { return ‘orange’; } }; var json = JSON.stringify({x: obj});
A. {“x”:”orange”}
B. {“fruit”:”apple”}
C. {“x”:”apple”}
D. {“fruit”:”orange”}
Ans: A
51. What types of values can you have in JSON key:value pairs?
A. Strings, Arrays, and Primitives
B. Arrays, Primitives, and Objects stored as strings
C. Strings, Arrays, Primitives and Objects
D. Strings only
Ans: C
52. What does JSONP stand for?
A. JSON Procedures
B. JSON Parsing
C. JSON with padding
D. JSON Programming
Ans: C
53. Which of the following code will not throw an error?
A. JSON.parse(”);
B. JSON.parse(null);
C. JSON.parse();
D. JSON.parse({});
Ans:B
54. How does JSON handle numeric values that cannot be represented by a sequence of digits (like Infiniti and Nan)?
A. They are stored as strings and then converted when parsed.
B. They are not permitted.
C. They are stored fine but it’s the parsers job to convert them to numeric values.
Ans: B
55. Which of the following number formats are not used in JSON?
A. Octal and gate
B. Octal and binary
C. Binary and hexadecimal
D. Octal and hexadecimal
Ans: D
56. What is used by the JSONObject and JSONArray constructors to parse JSON source strings?
A. JSONTokener
B. JSONParser
C. JParser
D. ParserJ
Ans: A
57. Which statement about the space parameter in JSON.stringify() is false?
A. It controls spacing in the resulting JSON string
B. All three statements are false
C. It removes whitespace
D. It is an optional parameter
Ans: C
58. True of False? The external form of a JSON object always begins and ends with {}
A. True
B. False
Ans: A
59. True of False. The order of JSON objects is always preserved.
A. False
B. True
Ans: A