title: Map[String,Any] to compact json string using json4s
body: <p>I am currently extracting some metrics from different data sources and storing them in a map of type <code>Map[String,Any]</code> where the key corresponds to the metric name and the value corresponds to the metric value. I need this to be more or less generic, which means that values types can be primitive types or lists of primitive types.</p>
  
  <p>I would like to serialize this map to a JSON-formatted string and for that I am using <code>json4s</code> library. The thing is that it does not seem possible and I don't see a possible solution for that. I would expect something like the following to work out of the box :)</p>
  
  <pre><code>val myMap: Map[String,Any] = ...    // extract metrics
  val json = myMap.reduceLeft(_ ~ _)  // create JSON of metrics
  </code></pre>
  
  <p>Navigating through <a href="https://github.com/json4s/json4s/blob/scala_2.10/ast/src/main/scala/org/json4s/JsonDSL.scala" rel="noreferrer">source code</a> I've seen <code>json4s</code> provides implicit conversions in order to transform primitive types to <code>JValue</code>'s and also to convert <code>Traversable[A]/Map[String,A]/Option[A]</code> to <code>JValue</code>'s (under the restriction of being available an implicit conversion from <code>A</code> to <code>JValue</code>, which I understand it actually means <code>A</code> is a primitive type). The <code>~</code> operator offers a nice way of constructing <code>JObject</code>'s out of <code>JField</code>'s, which is just a type alias for <code>(String, JValue)</code>.</p>
  
  <p>In this case, map values type is <code>Any</code>, so implicit conversions don't take place and hence the compiler throws the following error:</p>
  
  <pre><code>                    value ~ is not a member of (String, Any)
  [error]             val json = r.reduceLeft(_ ~ _)
  </code></pre>
  
  <p>Is there a solution for what I want to accomplish?</p>