I have a JSON file like this:
{"ID": "1234566", "Name": "abcd", "Hobby": "run"}
How can I parse that file and get the ID and Hobby?
I have a JSON file like this:
{"ID": "1234566", "Name": "abcd", "Hobby": "run"}
How can I parse that file and get the ID and Hobby?
 
    
     
    
    You can read json file using sqlContext.read.json(input) in Spark. 
Sample code with Spark version 1.6.2:
import org.apache.spark._
import org.apache.spark.sql.SQLContext;  
object JsonParser {
    val conf = new SparkConf().setAppName("Spark json extract")
             // Set this for debug mode on eclipse 
              conf.setMaster("local");
    val sc = new SparkContext(conf)
    val sqlContext = new SQLContext(sc)
    val input = "C:\\Users\\json_extract\\test1.json"
    def main(args: Array[String]): Unit = {
      val df = sqlContext.read.json(input)
      df.registerTempTable("jsonExtract")
      val data = sqlContext.sql("select * from jsonExtract")
      data.show();
    sc.stop
  }
}
