Skip to content

Instantly share code, notes, and snippets.

@vovanmix
Created February 17, 2017 03:52
Show Gist options
  • Save vovanmix/fb97f631cd0b3fdde0e16b324cb0d13b to your computer and use it in GitHub Desktop.
Save vovanmix/fb97f631cd0b3fdde0e16b324cb0d13b to your computer and use it in GitHub Desktop.
scala json parser
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