350-401 · Question #1190
Drag and Drop Question Drag and drop the code snippets from the bottom onto the blanks in the script to convert a Python object into a JSON string. Not all options are used. Answer:
The correct answer is JSONEncoder; .encode; data. To convert a Python object into a JSON string, you use json.JSONEncoder().encode(data). The JSONEncoder class is Python's built-in JSON encoder, and calling .encode(data) on an instance of it serializes the Python object (data) into a JSON-formatted string. This is the standard p
Question
Drag and Drop Question Drag and drop the code snippets from the bottom onto the blanks in the script to convert a Python object into a JSON string. Not all options are used. Answer:
Exhibit
Answer Area
Drag items
Correct arrangement
- JSONEncoder
- .encode
- data
Explanation
To convert a Python object into a JSON string, you use json.JSONEncoder().encode(data). The JSONEncoder class is Python's built-in JSON encoder, and calling .encode(data) on an instance of it serializes the Python object (data) into a JSON-formatted string. This is the standard pattern for manually encoding Python objects to JSON using the json module.
Topics
Community Discussion
No community discussion yet for this question.
