title: Convert spark dataframe into json files which contains array of json
body: <p>I am writing Spark Application in scala which reads the HiveTable and save the output in HDFS as Json Format file.</p>
  
  <p>I read the hive table using HiveContext and it returns the DataFrame. Below is the code snippet.</p>
  
  <pre><code>val sparkConf = new SparkConf().setAppName("SparkReadHive")
  val sc = new SparkContext(sparkConf)
  val sqlContext = new HiveContext(sc)
  
  import sqlContext.implicits._
  
      val df = sqlContext.sql(
        """
          |SELECT *
          |FROM database.table
          |""".stripMargin)
  
  df.write.format("json").save(path)
  </code></pre>
  
  <p>I need output file looks like below:</p>
  
  <pre><code>[{"name":"tom", "age": 8},
  {"name":"Jerry", "age": 7}]
  </code></pre>
  
  <p>However, what I get is like below:</p>
  
  <pre><code>{"name":"tom", "age": 8}
  {"name":"Jerry", "age": 7}
  </code></pre>
  
  <p>Can someone please help me with it? Thank you!</p>