title: spark streaming with json file
body: <p>I want to read json data from a folder location through spark streaming.</p>
  
  <p><strong>I assume my json data is</strong></p>
  
  <p>{"transactionId":111,"customerId":1,"itemId": 1,"amountPaid": 100}</p>
  
  <p><strong>I want the output in Spark SQL table as:--</strong></p>
  
  <pre><code>transactionId   customerId  itemId  amountPaid
      111              1         1       100
  </code></pre>
  
  <p><strong>my code is :</strong></p>
  
  <pre><code>package org.training.spark.streaming
  import org.apache.spark.streaming.StreamingContext._
  import org.apache.spark.streaming.{Seconds, StreamingContext}
  import org.apache.spark.{SparkConf, SparkContext}
  import org.apache.spark.sql.SQLContext
  import org.apache.spark.streaming.Duration
  import org.apache.spark.sql.functions.udf
  import org.training.spark.streaming.sqlstreaming.Persons
  
  object jsonread {
    def main(args: Array[String]) {
      val sparkConf = new SparkConf().setMaster("local").setAppName("jsonstreaming")
  
      val sc = new SparkContext(sparkConf)
  
      // Create the context
      val ssc = new StreamingContext(sc, Seconds(40))
      val lines = ssc.textFileStream("src/main/resources/fileStreaming")
      lines.foreachRDD(rdd=&gt;rdd.foreach(println))
  
      val words = lines.flatMap(_. split(","))
  
      words.foreachRDD(rdd=&gt;rdd.foreach(println))
      val sqc = new SQLContext(sc);
      import sqc.implicits._
  
      words.foreachRDD { rdd =&gt;
        val persons = rdd.map(_.split(":")).map(p =&gt; (p(0), p(1))).toDF()
  
        persons.registerTempTable("data")
  
        val jsontable = sqc.sql("SELECT * from data")
        jsontable.show
      }
      ssc.start()
      ssc.awaitTermination()
    }
  }
  </code></pre>