Loading

Quipoin Menu

Learn • Practice • Grow

python / Working with JSON
mcq
Direction: Choose the correct option

Q1.

Which module is used for JSON handling in Python?
A. simplejson
B. jsondata
C. pyjson
D. json
Direction: Choose the correct option

Q2.

What does `json.loads()` do?
A. Parses a JSON string into a Python object
B. Loads JSON from a file
C. Reads JSON from URL
D. Dumps Python object to JSON string
Direction: Choose the correct option

Q3.

How do you convert a Python dictionary to a JSON string?
A. json.dumps(dict)
B. json.encode(dict)
C. json.loads(dict)
D. json.stringify(dict)
Direction: Choose the correct option

Q4.

What does `json.load()` do?
A. Parses JSON URL
B. Reads JSON from a string
C. Writes JSON to a file
D. Reads JSON from a file-like object
Direction: Choose the correct option

Q5.

What is the output of `json.dumps({'a':1})`?
A. '{'a': 1}'
B. '{"a":1}'
C. '{"a": 1}'
D. '{"a":1}'
Direction: Choose the correct option

Q6.

How do you write a Python object to a JSON file?
A. json.write(obj, file)
B. json.save(obj, file)
C. json.dump(obj, file)
D. json.dumps(obj, file)
Direction: Choose the correct option

Q7.

What is the Python type of a JSON array after `loads()`?
A. set
B. tuple
C. dict
D. list
Direction: Choose the correct option

Q8.

How do you handle non-serializable objects like datetime?
A. All of the above
B. Use default argument
C. Use custom encoder subclassing JSONEncoder
D. Use `str()`
Direction: Choose the correct option

Q9.

What does `json.dumps(obj, indent=2)` do?
B. Pretty-prints JSON with 2 spaces
C. Adds newlines
D. Compresses JSON