Transform JSON array and assign to single value case class with Play JSON
<p>Given the following JSON object:</p>

<pre><code>{realtime-accesses: [
    {realtime-access: {
        level: 2
        marketID: 1
    }},
    {realtime-access: {
        level: 4
        marketID: 3
    }}
]
}
</code></pre>

<p>I want a Scala object that looks like this:</p>

<pre><code>RealTimeAccesses(Map(1-&gt;2,3-&gt;4))
</code></pre>

<p>This is the code Im trying to use:</p>

<pre><code>  case class RealTimeAccesses(markets: Map[Int, Int])
  object RealTimeAccesses {
    implicit val realTimeAccessesFormatter: Format[RealTimeAccesses] = (
      (__ \ "realtime_accesses").format[List[Map[String, Map[String, Int]]]].map(
        _.iterator
        .flatMap(_.values)
        .map { v =&gt; v("marketID") -&gt; v("level") }
        .toMap).inmap(m =&gt; RealTimeAccesses(m), (m: RealTimeAccesses) =&gt; m.markets))
  }
</code></pre>

<p>However this does not work, im getting can not resolve symbol on <code>inmap</code>.</p>

<p>My questions are:</p>

<ol>
<li>How can this transformation be done the way I want?</li>
<li>Is it possible to use <code>type RealTimeAccess = Map[Int,Int]</code> instead of a case class?</li>
</ol>