I have Row (org.apache.spark.sql.Row) which has the following schema StructField(testPref,StringType,true) , this "testPref" is in Json format which has value
{
"testPref":{
"institutionId":"001",
"currency":{
"default":"",
"padding":{
"direction":"left",
"value":" "
}
}
}
}
I am trying to read the value like below
val pref = row.getAs[String]("testPref")
My requirement is to convert to JSON format and parse it and access keys and values. How can i do this ?
Update :
I am able to convert it to JsonObject like below
val pref = row.getAs[String]("testPref")
val json: JsonObject = new JsonParser().parse(pref).getAsJsonObject
json.getAsJsonObject("currency").get("default").getAsString
to access json object