title: Dynamic JSON Creation in Play
body: <p>I'm trying to dynamically create a JSON object in the following way. Note that the below code will not compile as I'm requesting your help on how to code it.</p>
  
  <pre><code>val favoriteFoods: JsArray = getArray() // gets Array of Array of JSON objects
  
  val json: JsObject = Json.obj( 
     "name" : JsString("Kevin"),
     "FavoriteFood1" -&gt; favoriteFoods.get(0), // note that I made up the get()
     "FavoriteFood2" -&gt; favoriteFoods.get(1)
     )
  </code></pre>
  
  <p>Looking at the <a href="http://www.playframework.com/documentation/2.0/api/scala/play/api/libs/json/JsArray.html" rel="nofollow">JsArray</a> docs, I didn't see any way to get the <code>i'th</code> element of a JsArray.</p>
  
  <p>I tried to add an if statement to check if a new <code>FavoriteFood</code> could be added, but it would not compile.</p>