JSON MCQs – JSON Syntax and Basics

11.) What is the correct JSON format for a boolean value?

A) “true” or “false”
B) True or False
C) true or false
D) TRUE or FALSE

Answer: Option C

Explanation: JSON boolean values are true or false, written in lowercase and without quotes.

12.) Can a JSON object have duplicate keys?

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

Answer: Option B

Explanation: JSON keys must be unique within the same object.

13.) What happens when duplicate keys are present in a JSON object?

A) An error is thrown.
B) The first key-value pair is ignored.
C) The last key-value pair overrides the previous ones.
D) Both key-value pairs are stored.

Answer: Option C

Explanation: In JSON, duplicate keys are not allowed. If they occur, the last key-value pair takes precedence.

14.) Can JSON objects be nested inside other JSON objects?

A) Yes
B) No
C) Only with arrays
D) Only with strings

Answer: Option A

Explanation: JSON objects can be nested inside other objects or arrays, enabling complex structures.

15.) What is the root element of a JSON document?

A) An object or array
B) A string
C) A number
D) A key-value pair

Answer: Option A

Explanation: JSON documents must start with either an object {} or an array [].

16.) Which of the following is a valid JSON string?

A) ‘Hello’
B) “Hello”
C) Hello
D) “Hello”

Answer: Option D

Explanation: JSON strings must be enclosed in double quotes “.

17.) Which of these is a valid JSON array of strings?

A) [apple, banana, cherry]
B) [“apple”, “banana”, “cherry”]
C) [‘apple’, ‘banana’, ‘cherry’]
D) [“apple”, ‘banana’, “cherry”]

Answer: Option B

Explanation: JSON arrays of strings must use double quotes consistently around each string value.

18.) Which of the following is a valid JSON array?

A) {[1, 2, 3]}
B) [1, 2, 3]
C) (1, 2, 3)
D) <1, 2, 3>

Answer: Option B

Explanation: JSON arrays are enclosed in square brackets and separated by commas.

19.) Which of these is valid for a JSON number?

A) 1.23
B) 123e5
C) -456
D) All of the above

Answer: Option D

Explanation: JSON numbers can include decimals, exponents, and negatives.

20.) What happens if there is a syntax error in a JSON file?

A) It gets ignored.
B) The JSON file still works.
C) It will fail to parse.
D) It displays a warning but continues.

Answer: Option C

Explanation: JSON with syntax errors cannot be parsed and will throw an error.

Leave a Reply

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