Search Tutorials


JSON Quiz - MCQ - Multiple Choice Questions | JavaInUse

JSON Quiz - MCQ - Multiple Choice Questions

Q. What is JSON (JavaScript Object Notation)?

A. A data exchange format
B. A programming language
C. A web development framework
D. A database management system

Q. Which data types are supported by JSON?

A. String, Number, Boolean, Null, Object, and Array
B. String, Integer, Float, Boolean, and Array
C. String, Number, Boolean, and Null
D. Only String and Number

Q. How do you represent a JSON object?

A. Curly braces: {}
B. Square brackets: []
C. Angle brackets: <>>
D. Parentheses: ()

Q. How do you represent a JSON array?

A. Curly braces: {}
B. Square brackets: []
C. Angle brackets: <>
D. Parentheses: ()

Q. What is the correct way to write a JSON string?

A. "This is a JSON string"
B. 'This is a JSON string'
C. This is a JSON string
D. All of the above

Q. How do you represent a null value in JSON?

A. 0
B. false
C. null
D. undefined

Q. Can a JSON object contain another JSON object as a value?

A. Yes
B. No

Q. What is the purpose of JSON.stringify() method?

A. To convert a JSON string into a JavaScript object
B. To convert a JavaScript object into a JSON string
C. To format a JSON string for readability
D. To validate a JSON string

Q. What is the purpose of JSON.parse() method?

A. To convert a JSON string into a JavaScript object
B. To convert a JavaScript object into a JSON string
C. To format a JSON string for readability
D. To validate a JSON string

Q. What is the difference between JSON and XML?

A. JSON is more lightweight and widely used than XML.
B. XML supports more data types than JSON.
C. JSON uses curly braces, while XML uses angle brackets.
All of the above.

Q. How do you access a property of a JSON object in JavaScript?

A. obj.propertyName
B. obj[propertyName]
C. obj.getProperty(propertyName)
D. obj.get(propertyName)





Q. What is the correct way to write a multiline JSON string?

A. "This is a
multiline JSON string"
B. "This is a \n multiline JSON string"
C. 'This is a
multiline JSON string'
D. 'This is a \n multiline JSON string'

Q. How do you validate a JSON string?

A. Use a JSON validator tool
B. Check if it can be parsed by JSON.parse()
C. Both A and B
D. Neither A nor B

Q. What will be the output of JSON.stringify(true) in JavaScript?

A. "true"
B. true
C. "1"
D. 1

Q. Can a JSON array contain a JSON object as an element?

A. Yes
B. No

Q. Which of the following JSON objects is valid?

A.
{
    "name": "John",
    "age": 30,
    "address": "New York"
}
B.
{
    'name': 'John',
    age: 30,
    "address": "New York"
}
C.
{
    name: "John",
    age: 30,
    address: "New York"
}
D.
{
    "name": John,
    "age": 30,
    "address": "New York"
}

Q. What will be the output of parsing the following JSON string?

{"name": "Alice", "age": 25}
A.
{
    "name": "Alice",
    "age": "25"
}
B.
{
    name: "Alice",
    age: 25
}
C.
{
    "name": Alice,
    "age": 25
}
D.
An error occurs.

Q. Which of the following code snippets demonstrates the correct way to access the "name" value from a JSON object in JavaScript?

A.
const json = {"name": "Bob", "age": 35};
console.log(json.name);
B.
const json = {"name": "Bob", "age": 35};
console.log(json["name"]);
C.
const json = {"name": "Bob", "age": 35};
console.log(json.getName());
D.
const json = {"name": "Bob", "age": 35};
console.log(json.get("name"));

Q. What will be the output of the following code snippet?

const json = {"name": "Emily", "age": 28};
delete json.age;
console.log(json);
A.
{
    "name": "Emily"
}
B.
{
    "name": "Emily",
    "age": undefined
}
C.
{
    "age": 28
}
D.
An error occurs.

Q. Which of the following code snippets demonstrates the correct way to parse a JSON string in Python?

A.
import json

json_string = '{"name": "Mike", "age": 40}'
json_object = json.loads(json_string)
print(json_object)
B.
json_string = '{"name": "Mike", "age": 40}'
json_object = json.load(json_string)
print(json_object)
C.
json_string = json.loads('{"name": "Mike", "age": 40}')
print(json_string)
D.
json_string = '{"name": "Mike", "age": 40}'
json_object = json.parse(json_string)
print(json_object)

Q. What will be the output of the following code snippet in Python?

import json

json_data = {"name": "Olivia", "age": 22}
json_string = json.dumps(json_data)
print(json_string)
A.
{"name": "Olivia", "age": 22}
B.
{'name': 'Olivia', 'age': 22}
C.
{'name': "Olivia", age: 22}
D.
An error occurs.

Q. Which of the following JSON arrays is valid?

A.
[
    "apple", "banana", "cherry"
]
B.
[
    apple, banana, cherry
]
C.
[
    "apple", banana, "cherry"
]
D.
[
    'apple', 'banana', 'cherry'
]

Q. How to add a new key-value pair to an existing JSON object in JavaScript?

A.
const json = {"name": "David"};
json.add("age", 32);
B.
const json = {"name": "David"};
json["age"] = 32;
C.
const json = {"name": "David"};
json.set("age", 32);
D.
const json = {"name": "David"};
json.put("age", 32);

Q. What will be the output of the following code snippet in JavaScript?

const json = {"name": "Sophia", "age": 27};
const json_string = JSON.stringify(json);
console.log(typeof json_string);
A.
object
B.
string
C.
number
D.
boolean

Q. Which of the following code snippets demonstrates the correct way to parse a JSON string in Java?

A.
import org.json.JSONObject;

String json_string = "{\"name\": \"Michael\", \"age\": 38}";
JSONObject json_object = new JSONObject(json_string);
System.out.println(json_object.getString("name"));
B.
import org.json.JSONObject;

String json_string = "{\"name\": \"Michael\", \"age\": 38}";
JSONObject json_object = JSONObject.parse(json_string);
System.out.println(json_object.get("name"));
C.
import org.json.JSONObject;

JSONObject json_object = new JSONObject();
json_object.put("name", "Michael");
json_object.put("age", 38);
System.out.println(json_object.getString("name"));
D.
import org.json.JSONObject;

String json_string = "{\"name\": \"Michael\", \"age\": \"38\"}";
JSONObject json_object = new JSONObject(json_string);
System.out.println(json_object.getInt("age"));