Advanced JSON structures, such as nested objects, arrays, and mixed data types, are frequently encountered in modern applications. These structures are critical for modeling complex data in APIs and databases. The following MCQs are designed to provide insights into advanced JSON structures, ensuring you’re well-prepared for technical interviews and problem-solving tasks.
1.) Which of the following is an example of a nested JSON object?
A) { “name”: “John” }
B) { “person”: { “name”: “John”, “age”: 30 } }
C) [ “John”, 30 ]
D) { “name”: “John”, “age”: 30 }
2.) What does a JSON array of objects look like?
A) { “object1”: “value1”, “object2”: “value2” }
B) [ { “key”: “value” }, { “key”: “value” } ]
C) { “array”: [ “value1”, “value2” ] }
D) [ “object1”, “object2” ]
3.) Which of the following is valid JSON for a mixed data type array?
A) [ “Alice”, 25, true ]
B) [ { “name”: “Alice” }, 25, “true” ]
C) [ “Alice”, “25”, true ]
D) All of the above
4.) How do you access the name of the first employee in the above JSON structure?
A) department.employees[0].name
B) department.employees[1].name
C) employees[0].name
D) department[employees][name]
5.) How do you represent a key-value pair where the value is an array?
A) { “key”: { “value1”: “value2” } }
B) { “key”: [ “value1”, “value2” ] }
C) { “key”: “value1”, “value2” }
D) [ { “key”: “value1” } ]
6.) What is the output of JSON.stringify() on a nested object?
A) A string representation of the nested object
B) A flattened version of the object
C) A deep copy of the object
D) Throws an error
7.) What is the maximum depth for nesting in JSON?
A) Unlimited
B) 10 levels
C) 5 levels
D) Depends on the programming language and environment
8.) Which of the following is an invalid JSON structure?
A) { “key”: [1, 2, { “nested”: “value” }] }
B) { “key”: { “nested”: { “deep”: [1, 2] } } }
C) { “key”: “value”, “key”: “anotherValue” }
D) D)
9.) How can you find the length of an array inside a JSON object?
A) jsonObject.array.length
B) jsonObject.array.size()
C) jsonObject.array.count()
D) jsonObject.array.len
10.) What is the result of trying to access a non-existent key in a JSON object?
A) Throws an error
B) Returns null
C) Returns undefined
D) Returns an empty string
Related