Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package example
- import io.circe._, io.circe.generic.auto._, io.circe.parser._, io.circe.syntax._
- import io.circe.optics.JsonPath._
- object Hello extends App {
- val json = """
- {
- "iam" : {
- "teapot" : "Here is my snout"
- }
- }
- """
- case class Iam(teapot: String)
- val res = for {
- js <- parse(json)
- iam <- root.iam.as[Iam].
- getOption(js).toRight(ParsingFailure("iam field not specified", new Throwable))
- snout <- root.iam.teapot.string.
- getOption(js).toRight(ParsingFailure("couldnt get the teapot", new Throwable))
- } yield snout -> iam
- println(res)
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement