title: Play-Json Coast-to-Coast: Best Pattern for "Nesting" Transformations
body: <p>I'm becoming a fan of the play-json coast-to-coast pattern, especially its use of combinators. I have some complex cases I'm munging together. I know there's a better way, but I'm new to the combinator approach to build up functionality.</p>
  
  <p>I'd like to turn this:</p>
  
  <pre><code>{
   "somearray": [
     { 
       "field1": "value1",
       "field2": "value1",
       "key": "key1"
     },
     { 
       "field1": "second1",
       "field2": "second1",
       "key": "key2"
     }
    ]
   }
  </code></pre>
  
  <p>into this:</p>
  
  <pre><code>{
   "someObj": {
     "key1":
     { 
       "field1": "value1",
       "field2": "value1"
     },
     "key2":
     { 
       "field1": "second1",
       "field2": "second1"
     }
    ]
   }
  </code></pre>
  
  <p>I can get this to work, but I exit out of the transformation:</p>
  
  <pre><code> (__ \ "someObj").json.copyFrom(__ \ "someArray".json.pick.map {
     case JsArray(arr) =&gt; {
       JsObject(arr.map(a =&gt;
         a.transform(&lt;A transform function to prune key&gt;).map(pruned =&gt; {
           ((a \ "key").as[String], pruned)
         }).flatMap({
           case JsSuccess(result, _) =&gt; Seq(result)
           case other =&gt; Nil
         })
     }
     case other =&gt; JsNull
   })
  </code></pre>
  
  <p>THere are some issues with this code: I know it's verbose, I know I'm assume "key" is present with a string type, and I need that flatMap to get me out of a JsResult and into some JsValue I can use to build the JsObject.</p>
  
  <p>It seems like I should be able to</p>
  
  <p>1) Create a sub transformation, i.e. <code>a.transform()</code> can be nestled in the parent transform without unpacking and repacking the json object.</p>
  
  <p>Thank you.</p>