Trying to convert a dataframe to a JSON string and the output is just {}. Not sure what I'm doing wrong?
This is just a test but full Dataframe schema I need to use is 800+ columns so I don't want to have to specify each field specifically in the code if possible! Code runs in a locked down corporate environment so I can't write or read files to the system, has to be string output only.
import org.json4s.jackson.Serialization.write
import org.json4s.DefaultFormats
implicit val formats = DefaultFormats
val test = spark.sql("SELECT field1, field2, field3 FROM myTable LIMIT 2");
println("Output:");
write(test);
Output:
res12: String = {}
To add insult to injury, I could use the built in toJSON function (from scala.util.parsing.json._) but our corporate environment has set spark.sql.jsonGenerator.ignoreNullFields to True and it can't be changed but the output has to include null fields - hoping json4s can oblige :)
Thanks