title: How to get json response output using Play Framework(Scala) for json objects from Postgresql table?
body: <p>I am trying to return json response data from Postgresql database using Play framework(Scala). I have tried the following: but I am not able to return my json response output.(As I have couple of json objects in my database table: <code>jsondata</code>, which is having id and name). I am getting: "<code>type mismatch; found : anorm.SqlQuery required: String</code>". I am not sure where I am doing wrong in my code to get json response output for my json objects from database(controller and model). Please help me regarding this to get the output and Thanks in advance.</p>
  
  <p>controler: </p>
  
  <pre><code>import play.api.Play.current
  import play.mvc.Controller;           
  import play.libs.Json;
  import play.libs.Json.*;                        
  import com.fasterxml.jackson.databind.JsonNode;
  import org.codehaus.jackson.JsonNode;           
  import models.Getjsondata
  import com.google.gson.Gson
  import scala.util.{Try, Success, Failure}
  
   Getjsondata.getJsonValues(Getjsondata(Json.parse(id)), Json.parse(name));
   class MyController extends Controller {
   def getJson = Action { request =&gt;
      println("calling getJson ... !!")//getting this message on play console
      val body: Anyname = request.body
      val textBody: Option[String] = body.asText
      val optionJson = textBody.flatMap(json =&gt; Try(Json.parse(json)).toOption)
      val bodyId = optionJson.map(_ \ "id")
      val bodyname = optionJson.map(_ \ "name")
      {
        for {
          id &lt;- bodyId
          name &lt;- bodyname
          json &lt;- optionJson
        } yield {
          println("calling getJson else ... !!")
          val response = Getjsondata.getJsonValues(Getjsondata(id.as[Long],name.as[String]));
          Ok("Json data retrieved successfully: "+response)
        }
      } getOrElse BadRequest("Missing parameter either [id] or [name]")
    }
    }
  </code></pre>
  
  <p>model:</p>
  
  <pre><code>import anorm._
  import anorm.SqlParser._
  import play.api.db._
  import play.api.Play.current
  import play.api.libs.json.{Json,JsValue}
  import play.api.db.DB
  import play.api.libs.json._
  import anorm.~
  import play.api.libs.functional.syntax._
  
  case class Getjsondata (
    id: Pk[Long], name: String
  )
  object Getjsondata {
    val extractor = {
      get[Pk[Long]]("jsondata.id") ~
      get[String]("jsondata.name") map {
        case id~name =&gt; Getjsondata(id, name)
   }
   }
    def getJsonValues(jsondata: Getjsondata): String = {
    println("addJson getJsonValues page... !")
    DB.withConnection { implicit connection =&gt;
   // SQL("select row_to_json(jsondata) from jsondata");
      SQL("select * from jsondata");//type mismatch; found : anorm.SqlQuery required: String
       }
       println("Test String... !") 
    }
  }
  </code></pre>