apache-spark apache-spark-sql json scala

How to convert DataFrame to Json?

I have a huge JSON file, a small part from it as follows:

"socialNews": [{
"adminTagIds": "",
"fileIds": "",
"departmentTagIds": "",
"comments": [{
"commentId": "",
"newsId": "",
"entityId": "",

I have applied lateral view explode on socialNews as follows:

val rdd = sqlContext.jsonFile("file:///home/ashish/test")
val result = sqlContext.sql("select * from social LATERAL VIEW explode(socialNews) social AS comment")

Now I want to convert back this result (DataFrame) to JSON and save into a file, but I am not able to find any Scala API to do the conversion.
Is there any standard library to do this or some way to figure it out?