title: How to send results of a Scala StaticQuery SELECT query direct to JSON object
body: <p>In Scala how can I most directly send the results of a MySql query to a JSON string?  We're working within the "play" framework and are using "slick" to connect to MySQL, so I'm more specifically trying to results of a <a href="http://slick.typesafe.com/doc/1.0.1-RC1/sql.html" rel="nofollow">slick's StaticQuery</a> SELECT directly to a <a href="http://www.playframework.com/documentation/2.1.3/ScalaJson" rel="nofollow">play JsValue</a> object.  However any solution to the general problem is welcome.  </p>
  
  <p>The select parameters of the query string are inserted dynamically and they have known MySQL types, but I don't generally know the specific parameters or the number of them at compile time.</p>
  
  <p>I've got a feeling that there's a clever way to do this with case classes and Map objects, but I'm hoping that someone has already solved this problem more simply.  For example there is this related <a href="https://gist.github.com/kdonald/2137988" rel="nofollow">Java Gist</a>.</p>
  
  <p>For example I currently have:</p>
  
  <pre><code>import play.api.libs.json._
  import scala.slick.jdbc.{GetResult, StaticQuery =&gt; Q}
  
  ...
  
  case class SrResult(id: Int, user_id: Int, title: String)
  implicit val getSrResult = GetResult(r =&gt; SrResult(r.&lt;&lt;, r.&lt;&lt;, r.&lt;&lt;))
  
  val qSql = "SELECT id,user_id,title from MYTABLE LIMIT 10"
  val q = Q.queryNA[SrResult](qSql)
  </code></pre>
  
  <p>I will be inserting the "is,user_id,title" into the qSql string dynamically, so Q.queryNA's return type "SrResult" is not known at complile time. </p>
  
  <p>For completeness here is an example table that I'm working with:</p>
  
  <pre><code>CREATE TABLE `MYTABLE` (
    `ID` int(11) NOT NULL AUTO_INCREMENT,
    `USER_ID` int(11) NOT NULL,
    `TITLE` varchar(254) NOT NULL,
    `DESCRIPTION` text
    `ARCHIVED` tinyint(1) NOT NULL,
    `CREATED_AT` bigint(20) NOT NULL,
    `END_DATE` date NULL,
    PRIMARY KEY (`ID`),
    KEY `TEST_USER_INDEX` (`USER_ID`),
    CONSTRAINT `TEST_USER_FK` FOREIGN KEY (`USER_ID`) REFERENCES `USERS` (`ID`) ON DELETE NO ACTION ON UPDATE NO ACTION
  ) ENGINE=InnoDB AUTO_INCREMENT=1058 DEFAULT CHARSET=utf8;
  </code></pre>