Created
January 6, 2016 15:34
-
-
Save julien-truffaut/52221b461e1bb2d1d5cd to your computer and use it in GitHub Desktop.
Plated Json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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