Q:

change datatype of json string to Datetime in spark

i am feeding json files to spark. A value in it is of Datetime type but it is being converted to string type. I got a solution here which said to rebuild spark after changing InferSchema.scala file of it but i dont want to do it. Is there any way i can convert it while reading json files. Also can i convert it using spark sql after "jsonFiles.registerTempTable('jsonFiles')". Any help in this regard will be greatly appriciated. 

A:

With the jsonFile function you can also specify the schema at read time so:
sqlContext.jsonFile(path, schema) or in the new API (post 1.4) sqlContext.read.schema(schema).format("json").load(path)

