I am using spark data bricks cluster in azure, my requirement is to generate json and save json file to databricks storage
But I am getting below error
object of type rdd is not json serializable
code:
df = spark.read.format("csv") \
.option("inferSchema", False) \
.option("header", True) \
.option("sep", ",") \
.load("path-to-file")
df_json = df.toJSON()
file_out="out.json"
with open(file_out, 'w') as f:
json.dump(df_json, f)
How to fix the issue?



