i am trying to read sample Json file through Apache Spark, during this process i observed one thing is that you need to keep entire json object into single line. If i keep entire json object into single line,code is working well otherwise getting exception.
This is my json data:
[
{
"id": 2,
"name": "An ice sculpture",
"price": 12.50,
"tags": ["cold", "ice"],
"dimensions": {
"length": 7.0,
"width": 12.0,
"height": 9.5
},
"warehouseLocation": {
"latitude": -78.75,
"longitude": 20.4
}
},
{
"id": 3,
"name": "A blue mouse",
"price": 25.50,
"dimensions": {
"length": 3.1,
"width": 1.0,
"height": 1.0
},
"warehouseLocation": {
"latitude": 54.4,
"longitude": -32.7
}
}
]
This is my code:
SparkSession session = new SparkSession.Builder().appName("JsonRead").master("local").getOrCreate();
Dataset<Row> json = session.read().json("/Users/mac/Desktop/a.json");
json.select("tags").show();
In case of small datasets its okay, is any other way to process large json datasets?
tags' given input columns: [_corrupt_record];