JSON MCQs – Advanced JSON Structures

11.) How do you merge two JSON objects?

A) Use Object.assign()
B) Use JSON.merge()
C) Use array.push()
D) Use JSON.stringify()

Answer: Option A

Explanation: The Object.assign() method can be used to merge two JSON objects into one.

12.) What happens if a JSON object has circular references when using JSON.stringify()?

A) It converts successfully
B) It throws a TypeError
C) It returns an empty object
D) It skips the circular reference and continues

Answer: Option B

Explanation: JSON.stringify() does not support circular references and will throw a TypeError.

13.) Which data structure is not directly supported by JSON?

A) Array
B) Object
C) Set
D) String

Answer: Option C

Explanation: JSON does not support Set or Map directly; these must be converted to arrays or objects before serialization.

14.) How do you reference the parent key in a deeply nested JSON object?

A) JSON does not support parent references
B) Use parent() function
C) Use a library to navigate JSON paths
D) Use key.parent

Answer: Option A

Explanation: JSON itself does not support parent references; navigation must be managed externally.

15.) What happens if a key in a JSON object contains special characters?

A) It throws an error
B) The key must be enclosed in double quotes
C) The key is ignored
D) The special characters are escaped automatically

Answer: Option B

Explanation: JSON keys with special characters must be enclosed in double quotes to be valid.

16.) How do you handle very large JSON data efficiently in JavaScript?

A) Load the entire JSON object in memory
B) Use streaming parsers like JSONStream
C) Split the JSON file into multiple smaller files
D) Both B and C

Answer: Option D

Explanation: Efficient handling of large JSON data requires either streaming parsers or dividing the data into smaller files to avoid memory overload.

17.) What does the following JSON structure represent?

{
  "department": "HR",
  "employees": [
    { "name": "Alice", "id": 1 },
    { "name": "Bob", "id": 2 }
  ]
}
A) A single JSON object
B) A JSON object containing a nested array of objects
C) A JSON array containing objects
D) An invalid JSON structure

Answer: Option B

Explanation: This JSON object contains a key (employees) whose value is an array of objects.

18.) How do you access the value 30 in the following JSON structure?

{
  "person": {
    "name": "John",
    "age": 30
  }
}
A) person[age]
B) person.age
C) person->age
D) person(“age”)

Answer: Option B

Explanation: Dot notation is used to access the value of a nested key in a JSON object.

19.) How do you access the second object in this JSON array?

[
  { "id": 1, "name": "Alice" },
  { "id": 2, "name": "Bob" }
]
A) array(1)
B) array[2]
C) array[1]
D) array->1

Answer: Option C

Explanation: JSON arrays are zero-indexed, so array[1] refers to the second element.

Leave a Reply

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