How to save files in different file formats other than textfile along with compression


Can you help me with the command to save file in different file formats json avro and parquet file format.

I tired saving the data frames using below commands with compression and the commands are failing."/filepath ",“parquet”,“snappy”)"/filepath ",“json”,“snappy”)

Data.toJSON().saveAsTextFile(“path”,“compressionCodecClass=”"") – this commands seems to work fine but the file save doenst have .json extension