Scala read file and load in list as json object
<p>I am trying to read a csv file using Scala and store the output as a list of Json (<code>list(json.obj)</code>). </p>

<p>Here is my code:</p>

<pre><code>def index = Action {
  Logger.info("Application startup...")
  var posts = List(Json.obj())
  var finalPost = List(Json.obj())
  val bufferedSource = Source.fromFile("/Users/manujkathuria/a.csv")
  for (line &lt;- bufferedSource.getLines) {
    val cols = line.split(",").map(_.trim)
    posts = List(
      Json.obj(
        "name" -&gt; cols(0),
        "age" -&gt; cols(1),
        "job" -&gt; cols(2)
      ))
    finalPost +: posts
  }
  bufferedSource.close
}
</code></pre>

<p>So my target is to store the data which I read from a.csv file and load it in the list of <code>jsonObjects</code> which I will use later for loading into MongoDB.</p>