Created
February 17, 2017 03:52
-
-
Save vovanmix/fb97f631cd0b3fdde0e16b324cb0d13b to your computer and use it in GitHub Desktop.
scala json parser
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._, io.circe.parser._ | |
import cats._ | |
import cats.data.Xor | |
val raw = """ | |
{ | |
"key" : "value", | |
"lorem" : "ipsum" | |
} | |
""" | |
// val parsed = decode[Map[String, String]](raw).getOrElse(Json.Null) | |
val parsed: Map[String, String] = decode[Map[String, String]](raw) match { | |
case Xor.Right(b) => b | |
} | |
//println(parsed) | |
val queries: Iterable[String] = parsed map { | |
case (key, value) => s"""INSERT INTO copies (`slug`, `page`, `kind`, `value`, `language`) VALUES ("$key", "layout", "", "$value", "en");""" | |
} | |
queries.foreach(println(_)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment