350-401 · Question #1006
Which statement must be used to export the contents of the devices object in JSON format?
The correct answer is D. json.dumps(Devices). Explanation json.dumps() is the correct method for converting a Python object (like the Devices dictionary) into a JSON-formatted string - the "s" in dumps stands for "string," making it ideal for exporting or serializing data in JSON format. Option A (json.repr) does not exist i
Question
Which statement must be used to export the contents of the devices object in JSON format?
Options
- Ajson.repr(Devices)
- Bjson.loads(Devices)
- Cjson.print(Devices)
- Djson.dumps(Devices)
How the community answered
(18 responses)- A6% (1)
- C6% (1)
- D89% (16)
Explanation
Explanation
json.dumps() is the correct method for converting a Python object (like the Devices dictionary) into a JSON-formatted string - the "s" in dumps stands for "string," making it ideal for exporting or serializing data in JSON format. Option A (json.repr) does not exist in the json module; repr() is a built-in Python function unrelated to JSON serialization. Option B (json.loads) is the opposite operation - it parses a JSON-formatted string back into a Python object, so it would be used for importing, not exporting. Option C (json.print) is entirely fictitious and not a real method in the json module.
Memory Tip
Think of it this way:
dumps= Dump to String (export Python → JSON string)loads= Load from String (import JSON string → Python)
The "s" at the end of both dumps and loads always signals you're working with a string, helping you remember which direction the data is flowing.
Topics
Community Discussion
No community discussion yet for this question.