Trying to create a StructType from a JSON file to be used as schema for creating a dataframe.
JSON structure:
{
"type" : "struct",
"fields" : [
{
"name" : "LocationID",
"type" : "int",
"nullable" : false,
"metadata" : { }
}, {
"name" : "Boroght",
"type" : "string",
"nullable" : true,
"metadata" : { }
}, {
"name" : "zone",
"type" : "string",
"nullable" : true,
"metadata" : { }
}, {
"name" : "serviceZone",
"type" : "string",
"nullable" : true,
"metadata" : { }
} ]
}
Reading JSON file and creating StructType:
val schemaSource = Source.fromFile(url.getFile).mkString
val schemaFromJson = DataType.fromJson(schemaSource).asInstanceOf[StructType]
I keep getting the error:
java.lang.IllegalArgumentException: Failed to convert the JSON string 'int' to a data type.
Not sure if it's the JSON structure or what to change there.
Type of LocationID should be integer not int.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With