JSON MCQs

JSON MCQs

These JSON multiple-choice questions and their answers will help you strengthen your grip on the subject of JSON. You can prepare for an upcoming exam or job interview with these JSON MCQs.
So scroll down and start answering.

1: JSON name/value pair is written as

A.   name = "value"

B.   name = 'value'

C.   name' : 'value'

D.   "name" : "value"

2: The following is valid JSON: {"method": ["function(x) { return x + 1; }"]}

A.   True

B.   False

3: What two structures is JSON built on?

A.   A collection of name/value objects, and an ordered list of objects, or array.

B.   A collection of name/value pairs, and an ordered list of values, or array.

C.   A collection of native-value pairs, and an ordered list of arrays, or values.

D.   A collection of object/item pairs, and an ordered list of pairs, or array.

4: What is used by the JSONObject and JSONArray constructors to parse JSON source strings?

A.   JSONTokener

B.   JSONParser

C.   ParserJ

D.   JParser

5: Which statement about the space parameter in JSON.stringify() is false?

A.   It controls spacing in the resulting JSON string

B.   It is an optional parameter

C.   All three statements are false

D.   It removes whitespace

6: Any valid JavaScript can be serialized into JSON.

A.   True

B.   False

7: Which of the following number formats are not used in JSON?

A.   Octal and hexadecimal

B.   Octal and binary

C.   Binary and hexadecimal

D.   Octal and gate

8: Which of the following is not a valid way to parse JSON string?

A.   JSON.eval()

B.   eval()

C.   jQuery.parseJSON()

D.   JSON.parse()

9: What does JSONP stand for?

A.   JSON Parsing

B.   JSON Procedures

C.   JSON with padding

D.   JSON Programming

10: How does JSON handle numeric values that cannot be represented by a sequence of digits (like Infiniti and Nan)?

A.   They are not permitted.

B.   They are stored as strings and then converted when parsed.

C.   They are stored fine but it's the parsers job to convert them to numeric values.

11: Which of the following code will not throw an error?

A.   JSON.parse('');

B.   JSON.parse(null);

C.   JSON.parse();

D.   JSON.parse({});

12: What error does JSON.parse() throw when the string to parse is not valid JSON?

A.   TypeError

B.   SyntaxError

C.   ReferenceError

D.   EvalError

13: How does JSON being "lightweight" translate into a benefit for the site visitors?

A.   Parsing JSON is noticeably faster than parsing XML

B.   Faster transfer times over the internet

C.   Web apps have a smaller footprint

14: 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.   {"x":{"Monday":true,"Wednesday":true,"Sunday":false}}

B.   {"day":{"Monday":"true","Wednesday":"true","Sunday":"false"}}

C.   {"day":{"Monday":true,"Wednesday":true,"Sunday":false}}

D.   {"x":["Monday":true,"Wednesday":true,"Sunday":false]}

15: In what situation would you want to use XML over JSON?

A.   When JSON is not offered.

B.   Never, JSON is worlds better.

C.   When you need to use tags to structure your content.

D.   You need message validation or you're using XSLT.

16: 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 JSON ordered pairs.

D.   It is used to create number strings in JSON.

17: 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.   {"Orange"}

B.   { "fruit" : "Apple"}

C.   {"Apple"}

D.   { "fruit" : "Orange"}

18: What types of values can you have in JSON key:value pairs?

A.   Strings, Arrays, Primitives and Objects

B.   Strings, Arrays, and Primitives

C.   Strings only

D.   Arrays, Primitives, and Objects stored as strings

19: 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":"apple"}

B.   {"fruit":"orange"}

C.   {"x":"orange"}

D.   {"fruit":"apple"}

20: Which of the following control characters cannot be used when writing a JSON string without escaping?

A.   / or {

B.   < or >

C.   ; or :

D.   “ or \

21: 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.   {"cars":["Ford","Toyota","BMW"]}

B.   {"x":["Ford","Toyota","BMW"]}

C.   {"x":['Ford','Toyota','BMW']}

D.   {"x":{"Ford","Toyota","BMW"}}

22: JSON strings have to be in

A.   double quote

B.   single quote

C.   single quote or double quote

23: Does whitespace matter in JSON?

A.   Yes, only within strings.

B.   No, it will be stripped out.

C.   Yes, only outside of strings.

D.   Yes, both inside and outside of strings

24: When coding a string object in JSON, what must separate the string and the value?

A.   A comma

B.   A colon

C.   A space

D.   A semicolon

25: True or false? The order of elements in JSON arrays is always preserved.

A.   True

B.   False

26: Which of these is supported as a JSON Value type?

A.   Infiniti

B.   Undefined

C.   NaN

D.   Null

27: What is JSONP meant to mitigate?

A.   Future proofing JSON as JavaScript changes.

B.   Size constraints of JSON

C.   Cross-domain communication

28: Does JSON support Unicode characters?

A.   No, JSON has no support for any kind of character encoding.

B.   Yes, JSON has support for Unicode characters. Allowing for almost any information in any human language

C.   Yes, only when stored as the key in a ( key : value ) pair.

D.   No, JSON only has support for UTF-8 characters.

29: In this example, what would the TYPE of employee.hireDate be? { "employee" : { "type" : "Director", "functions" : ['sales', 'marketing'], "hireDate" : "March 8, 2011" } }

A.   Number

B.   String

C.   March 8, 2011

D.   Date

30: In this example, what is the VALUE of employee.type? { "employee" : { "type" : "Director", "functions" : ['sales', 'marketing'] } }

A.   String

B.   Director

C.   Object

31: What function will convert a JavaScript object to a JSON string?

A.   JSON.toString()

B.   JSON.serialize()

C.   JSON.stringify()

D.   JSON.text()

32: What is the MIME type of JSON?

A.   application/json

B.   application/javascript

C.   text/json

D.   application/x-json

33: Which of the following code will throw an error?

A.   JSON.parse('{}');

B.   JSON.parse(null);

C.   JSON.parse(undefined);

D.   JSON.parse('[]');

34: In this example, what would the VALUE of employee.functions[1] be? { "employee" : { "type" : "Director", "functions" : ['sales', 'marketing'] } }

A.   undefined

B.   null

C.   marketing

D.   sales

35: True or false? A disadvantage of JSON is that it requires the use of JavaScript.

A.   False, JavaScript must be available although it is not necessary to use.

B.   True, though all browsers have JavaScript enabled.

C.   False, JSON is language independent.

D.   True, though JavaScript is readily available in today's browsers.

36: 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'}");

37: Which is true about JSON namespacing?

A.   JSON namespaces can be accessed immediately after receiving data.

B.   JSON doesn't have namespaces. Though every object is inherently a namespace.

C.   JSON namespaces can be accessed after parsing data.

38: Which of these data interchange formats has seen a decline in usage in favor of JSON?

A.   Plain-text

B.   XML

C.   SQL

D.   ASCII

39: 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" } ]

40: Which statement about the toJSON method is true?

A.   It allows an object to determine its own JSON representation

B.   All three statements are true

C.   It is internally called by JSON.stringify()

D.   It customizes JSON stringification behavior

41: In this example, what is the TYPE of employee.functions? { "employee" : { "type" : "Director", "functions" : ['sales', 'marketing'] } }

A.   Sales, Marketing

B.   String

C.   Array

D.   Object

42: Which statement about the reviver parameter in JSON.parse() is true?

A.   A function that will be called for every key and value at every level of the final result

B.   Used to reform generic objects into instances of pseudo-classes

C.   Each value will be replaced by the result of the reviver function

D.   All three statements are true

43: JSON elements are separated by

A.   white space

B.   semi-colon

C.   line break

D.   comma

44: What kind of format is JSON, and what does the acronym mean?

A.   A lightweight data-interchange format. JavaScript Object Notation.

B.   A lightweight database framework. JavaScript Object Notation.

C.   A lightweight data-interchange format. Java Objective Notion.

D.   A lightweight data-encoding framework. Java Omnipresent Notation.

45: What keywords are reserved in JSON and cannot be used as keys?

A.   Key

B.   Object

C.   There are none.

D.   Value

46: 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.   If an array, specifies the names of the properties in the object to include in the resulting JSON string

D.   All three statements are true

47: In this example, what is the TYPE of employee? { "employee" : { "type" : "Director", "functions" : ['sales', 'marketing'] } }

A.   String

B.   type

C.   Object

D.   Director

48: 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"; ] }

49: Which answer represents the following order of TYPES? Object, String, Boolean, Number

A.   { }, "0", false, 0

B.   { }, hello, "false", "0"

C.   "{ }", "a string", "false", "0"

D.   [ ], 0, "true", "0"

50: What does JSON stand for?

A.   JavaScript Object Notation

B.   JavaScript Objective Notation

C.   JavaScript Object Nomenclature

D.   JavaScript Orientated Nomenclature