I have JSON files describing a table structure. I want to read each file from S3 as a single String in order to then apply a fromJson() method of apache.spark.sql.types.DataType
DataType.fromJson(jsonString).asInstanceOf[StructType]
But for now I only managed to read the files into a DataFrame:
val testJsonData = sqlContext.read.option("multiline", "true").json("/s3Bucket/metrics/metric1.json")
But I don't need a df.schema, instead I need to parse the contents of a JSON string to a StructType.
The contents of a JSON file:
{
"type" : "struct",
"fields" : [ {
"name" : "metric_name",
"type" : "string",
"nullable" : true,
"metadata" : { }
}, {
"name" : "metric_time",
"type" : "long",
"nullable" : true,
"metadata" : { }
}, {
"name" : "metric_value",
"type" : "string",
"nullable" : true,
"metadata" : { }
}]
}