I am new to spark and Scala and I am trying to learn spark for one of my learning project. I have a JSON file which look like this:
[
{
"year": 2012,
"month": 8,
"title": "Batman"
},
{
"year": 2012,
"month": 8,
"title": "Hero"
},
{
"year": 2012,
"month": 7,
"title": "Robot"
}
]
I started reading this json to spark DataFrame file so i tried following:
spark.read
.option("multiline", true)
.option("mode", "PERMISSIVE")
.option("inferSchema", true)
.json(filePath)
It reads the JSON but convert the data to spark columns. My requirement is to read each data object as one individual column.
I want to read it to a spark DataFrame where I expect output like following:
+----------------------------------------+
|json |
+----------------------------------------+
|{"year":2012,"month":8,"title":"Batman"}|
|{"year":2012,"month":8,"title":"Hero"} |
|{"year":2012,"month":7,"title":"Robot"} |
|{"year":2011,"month":7,"title":"Git"} |
+----------------------------------------+