JSON MCQs – JSON Data Types

21.) What error occurs if you try to parse the following JSON?

'{"name": "Alice", "age": 25,}'
A) Trailing comma error
B) Type error
C) Key missing error
D) No error, valid JSON

Answer: Option A

Explanation: JSON does not allow trailing commas after the last key-value pair.

22.) What is the result of parsing this JSON string?

'{"key1": "value1", "key2": [1, 2, value3]}'
A) value3 is ignored
B) JSON is parsed successfully
C) value3 is converted to a string
D) Syntax error due to value3

Answer: Option D

Explanation: JSON does not support unquoted strings. value3 must be enclosed in double quotes.

23.) What will happen if you try to parse this JSON?

'["value1", , "value2"]'
A) Syntax error due to missing value
B) The missing value is converted to null
C) The JSON is parsed successfully
D) The missing value is ignored

Answer: Option A

Explanation: The JSON [“value1”, , “value2”] is invalid due to the missing value between the commas. JSON requires that each element in an array be a valid JSON value (such as a string, number, object, array, boolean, or null). A missing value results in a syntax error.

24.) What will happen when parsing the following JSON?

'{"key1": "value1", {"key2": "value2"}}'
A) The second object is ignored
B) JSON is parsed successfully
C) Syntax error due to misplaced object
D) key2 is treated as a nested key

Answer: Option C

Explanation: JSON objects must follow the correct structure. A standalone object cannot appear without a key.

25.) What is the output of parsing this JSON?

'{"key": "value" "key2": "value2"}'
A) {“key”: “value”, “key2”: “value2”}
B) Syntax error due to missing comma
C) {“key”: “valuekey2”: “value2”}
D) Null is assigned between the keys

Answer: Option B

Explanation: JSON keys must be separated by a comma. Missing a comma results in a syntax error.

Leave a Reply

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