lundi 20 avril 2015

Dealing with JSON in Scala?

In Scala 2.11, having the below code:

import play.api.libs.json._
val data = // read json from file                             (3)
val JSON: JsValue = Json.parse(data mkString "\n")            (4)
val items = JSON \ "items"
for (i <- 0 until 100) yield items(i)

  1. if I unite the last two lines for (i <- 0 until 100) yield (JSON \ "items")(i), will the term JSON \ "items" be evaluated for each i or only once?
  2. is it worth to parallelise the list construction with this for-expression (I don't care about the order in which items will appear in the list), where items is an array of JSON objects?
  3. what is the best way to handle exceptions from parsing the JSON in the lines (3 - 4) and validate it?

Aucun commentaire:

Enregistrer un commentaire