Skip to content

Instantly share code, notes, and snippets.

@julien-truffaut
Created January 6, 2016 15:34
Show Gist options
  • Save julien-truffaut/52221b461e1bb2d1d5cd to your computer and use it in GitHub Desktop.
Save julien-truffaut/52221b461e1bb2d1d5cd to your computer and use it in GitHub Desktop.
Plated Json
import io.circe.Json
import io.circe.optics.all._
import io.circe.parse.parse
import monocle.Iso
import monocle.function.Plated
import monocle.function.all._
object PlatedExample extends App {
val json =
"""{
| "name" : "john",
| "age" : 24,
| "other" : {
| "name" : "robert",
| "age" : 12
| }
|}
""".stripMargin
val doc: Json = parse(json).getOrElse(Json.empty)
universe(doc)
.map(_.asObject.flatMap(_("name")))
.collect{case Some(a) => a }
.foreach(println)
// "john"
// "robert"
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment