I have a dataframe with two columns. Each column contains json.
cola | colb |
---|---|
{"name":"Adam", "age": 23} | {"country" : "USA"} |
I wish to convert it to:
cola_name | cola_age | colb_country |
---|---|---|
Adam | 23 | USA |
How do I do this?
The approach I have in mind is: In the original dataframe, If I can merge both the json to a single json object. I can then obtain the intended result
spark.read.json(df.select("merged_column").as[String])
But cant find an easy way of merging two json object to single json object in spark
Update: The contents of the json is not known pre-hand. Looking for a way to auto-detect schema