Extraction an array from JSON string in spark

60 Views Asked by At

I am receiving a JSON String on kafka topic of form

{"user_id":"4BtIrO4vgJUZG3wUxDjihnKbYvw2","travel_mode":"plane","travel_with":["family","couple"],"travel_preferences":"national"}

Now I am using this JSON String in spark and extracting it by

var jValue: JValue=net.liftweb.json.JsonParser.parse(st)
val mailServer = jValue.extract[Reg]

by this I am able to extract all the other things except travel_with which is an array. So please tell me how to extract that array.

Please help

1

There are 1 best solutions below

0
Anonymous On

write a case class Reg of the form case class Reg(user_id: String, travel_mode: String, travel_with: List[String],travel_preferences: String) and then you will get travel_with of the form List[ a, b]