200-901 Question 5
Single answerYou are building a Python application that consumes data from an API that returns JSON. Which library and method combination should you use to parse the JSON data into a Python dictionary?
- A
xml.etree.ElementTree and ElementTree.parse()
- B
json and json.loads()
- C
yaml and yaml.load()
- D
csv and csv.reader()
Show answer and explanation
Correct answer: B
Explanation
To parse JSON data into a Python dictionary, the 'json' library is used along with the 'json.loads()' method. This method takes a JSON-formatted string and converts it into a Python data structure such as a dictionary or list. Other libraries such as xml.etree.ElementTree, yaml, and csv are used to parse other data formats like XML, YAML, and CSV, respectively.
- A. Incorrect.
xml.etree.ElementTree and ElementTree.parse() are used for parsing XML data, not JSON.
- B. Correct.
json and json.loads() is the correct combination for parsing JSON data into a Python dictionary.
- C. Incorrect.
yaml and yaml.load() is used for parsing YAML data, not JSON.
- D. Incorrect.
csv and csv.reader() is used for parsing CSV data, not JSON.