Databricks Certified Associate Developer for Apache Spark — Question 43
Which of the following code blocks writes DataFrame storesDF to file path filePath as JSON?
Answer options
- A. storesDF.write.option("json").path(filePath)
- B. storesDF.write.json(filePath)
- C. storesDF.write.path(filePath)
- D. storesDF.write(filePath)
- E. storesDF.write().json(filePath)
Correct answer: B
Explanation
The correct answer, B, directly uses the .json() method to write the DataFrame as JSON to the specified file path. Option A incorrectly uses the .option() method, which does not properly specify the JSON format for writing. Options C and D do not specify the JSON format at all, and option E is syntactically correct but less direct than option B.