1. Apache Spark 3.5.1 Official Documentation
pyspark.sql.DataFrameWriter:
For Option A: The documentation shows the mode(saveMode) method
which sets the SaveMode
and the json(path
...) method
which saves the content in JSON format. The standard usage is to chain these: df.write.mode('overwrite').json(path).
For Option D: The documentation for the save(path=None
format=None
mode=None
...) method explicitly lists mode as a parameter. This confirms that df.write.format('json').save(path
mode='overwrite') is a valid syntax.
For Options B and C: The API documentation confirms the absence of a .overwrite method and an overwrite parameter within the .json() method
invalidating these options.
2. Databricks Official Documentation
"Read and write JSON files":
The documentation provides examples for writing data. The standard syntax shown for overwriting is df.write.mode("overwrite").json("/tmp/my-json-file")
which directly supports the correctness of Option A. It also explains the different save modes
including overwrite.