JSON MCQs – JSON Data Types

11.) Which of the following data types can JSON arrays contain?

A) Only strings
B) Only numbers
C) Mixed data types
D) Only objects

Answer: Option C

Explanation: JSON arrays can contain elements of mixed data types, including numbers, strings, and objects.

12.) Can a JSON object be empty?

A) Yes
B) No
C) Only in arrays
D) Only in objects

Answer: Option B

Explanation: JSON does not support functions as values.

13.) Can a JSON object be empty?

A) Yes
B) No
C) Only in arrays
D) Only when nested

Answer: Option A

Explanation: JSON objects can be empty, represented as {}.

14.) Which of the following values can be used as JSON keys?

A) Strings only
B) Strings and numbers
C) Strings and booleans
D) Any data type

Answer: Option A

Explanation: JSON keys must always be strings enclosed in double quotes.

15.) Which of the following values is not valid in JSON?

A) “Hello”
B) 123
C) undefined
D) null

Answer: Option C

Explanation: JSON does not support the undefined value; use null to represent no value.

16.) Which of the following is the correct JSON format for a key-value pair?

A) {key: value}
B) {key = value}
C) {“key”: value}
D) {“key”: “value”}

Answer: Option D

Explanation: Both keys and string values must be enclosed in double quotes in JSON.

17.) Which of the following is true about JSON numbers?

A) They must include a decimal point.
B) They cannot be negative.
C) They support both integers and floats.
D) They must be enclosed in double quotes.

Answer: Option C

Explanation: JSON numbers can be integers or floating-point values and do not require quotes.

18.) Which of these is NOT allowed in JSON arrays?

A) Mixed data types
B) Nested arrays
C) Objects as elements
D) Functions as elements

Answer: Option D

Explanation: JSON arrays can contain mixed data types, nested arrays, or objects, but not functions.

19.) Can JSON objects contain duplicate keys?

A) Yes, with an error
B) No
C) Yes, the last key-value pair overrides the previous ones
D) Yes, but only for strings

Answer: Option C

Explanation: If duplicate keys are present, the last one defined in the object will overwrite the earlier ones.

20.) What will be the result of parsing the following JSON?

'{"name": "Alice", "age": "25", "age": "30"}'
A) Syntax Error
B) Both age values are stored
C) The first age value is kept
D) The second age value overrides the first

Answer: Option D

Explanation: JSON does not allow duplicate keys. When duplicate keys are present, the last one overrides the earlier ones.

Leave a Reply

Your email address will not be published. Required fields are marked *