Skip to content

Instantly share code, notes, and snippets.

@txominpelu
Created December 18, 2013 13:21
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save txominpelu/8022212 to your computer and use it in GitHub Desktop.
Save txominpelu/8022212 to your computer and use it in GitHub Desktop.
Retrieving rates from json object
import play.api.libs.json._
import play.api.libs.ws.WS
import scala.concurrent.ExecutionContext.Implicits._
import scala.concurrent.Await
import scala.concurrent.duration._
// Just for the example in the console - Await is WRONG
val result = WS.url("http://openexchangerates.org/api/latest.json?app_id=47b18507ef684bfd859ad93e21f3a226").get()
val json = Await.result(result, DurationInt(5).seconds).json
// This is the part to retrieve the keys
val rates = ( __ \ "rates").read[JsObject].reads(json)
rates.map(_.keys)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment