Answering my own question (for those who are interested):

val schema = df.schema
val jsonString = schema.json
val backToSchema = DataType.fromJson(jsonString).asInstanceOf[StructType]




From: Mendelson, Assaf [mailto:assaf.mendel...@rsa.com]
Sent: Sunday, December 04, 2016 11:11 AM
To: user
Subject: Creating schema from json representation

Hi,

I am trying to save a spark dataframe schema in scala.
I can do df.schema.json to get the json string representation.
Now I want to get the schema back from the json.
However, it seems I need to parse the json string myself, get its fields object 
and generate the fields manually.
Is there a better way?
Assaf.

Reply via email to