I have tried to send the json request and receive the json response and I am converting the json contents to Dataframe but the schema is string for all attributes.Is there anyway to apply my custom schema to the json response that is stored in datasets using scala and spark.
val inputStream = entity.getContent()
content = scala.io.Source.fromInputStream(inputStream).getLines.mkString
inputStream.close
}
httpClient.getConnectionManager().shutdown()
println(content)
val rootelem = "data"
var JsonDF : Dataframe = null;
if (rootelem.equalsIgnoreCase("NULL"))
{
jsonDF = sqlContext.read.json(Seq(content).toDS)
}
else{jsonDF=sqlContext.read.json(Seq(content).toDS).select(explode(col(rootelem)). as("child").select(col("child.*"))
jsonDF.show()
}}