How to return json from Play Scala controller?
<p>I would like to know that how can I return json response data from Play(2.2.x) Scala controller class to display on my view page ? I have json objects in Postgresql database(table name: "test" and having: id and name). Please provide me any solutions for it.</p>

<p>I have tried the following cases(a and b), but I am not sure why I am not getting the response(like: names) on my controller, so I can show them on my view page ? since I am very new to Play/Scala and Postgresql.
case a. If I give like:
model:</p>

<pre><code>def getTestValuesFromTable()   =  {
  DB.withConnection { implicit connection =&gt;
  val selectJson =SQL("select name from test").on().apply().collect {  
            case Row(id:Long, Some(name:String)) =&gt; 
            new TestContent(name)
         }
         //.head
         //JsObject(selectJson().map { row =&gt; row[Long]("id").toString -&gt; JsString(row[String]("name")) }.toSeq)
  }
  }
</code></pre>

<p>controller:</p>

<pre><code>def getTest = Action { 
      val response = TestContent.getTestValuesFromTable()
       Ok("Done")
      //Ok(response)
   }
</code></pre>

<p>Output is: Done(application is executing fine without any exceptions, of course json data is not coming since I am returning: Done only, so  getting output: "Done")</p>

<p>case b. If I do like this: getting error: not enough arguments for method apply: (n: Int)models.Testname in trait LinearSeqOptimized. Unspecified value parameter n. I really not sure how can I get my response for it ?</p>

<p>controller:</p>

<pre><code>def getTest = Action { 
      val response = TestContent.getTestValuesFromTable()
      // Ok("Done")
      Ok(response)
   }
</code></pre>

<p>model:</p>

<pre><code>def getTestValuesFromTable(): JsValue = {
 DB.withConnection { implicit connection =&gt;
   val selectJson = SQL("select * from test")
    JsObject(selectJson().map { row =&gt; row[Long]("id").toString -&gt; JsString(row[String]("name")) }.toSeq)
    // val selectJson =SQL("select name from test").on().apply().collect {  
           // case Row(id:Long, Some(name:String)) =&gt; 
           // new TestContent(name)
        // }
         //.head
    JsObject(selectJson().map { row =&gt; row[Long]("id").toString -&gt; JsString(row[String]("name")) }.toSeq)//not enough arguments for method apply: (n: Int)models.Testname in trait LinearSeqOptimized. Unspecified value parameter n.
    }
  }
</code></pre>

<p>Please let me know how to get my response ?</p>