cats typeclass instances for play-json
Switch branches/tags
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
project
src
.gitignore
.scalafmt.conf
.travis.yml
LICENSE
README.md
build.sbt

README.md

Build Status Maven Central

play-json-cats

cats typeclass instances for the play-json library.

Adding as a dependency to your project

libraryDependencies += "com.iravid" %% "play-json-cats" % 1.1.0

play-json-cats is cross-published for Scala 2.11 and 2.12.

Usage

import cats.implicits._
import com.iravid.playjsoncats.implicits._
import play.api.libs.json._

case class Person(name: String, i: Int)

val rn: Reads[String] = Reads(j => (j \ "name").validate[String])
val ri: Reads[Int] = Reads(j => (j \ "i").validate[Int])
val rp: Reads[Person] = (rn, rp).mapN(Person)

val res: JsResult[Person] = rp.reads(Json.parse("""
  { "name": "iravid", "i": 42 }
"""))

Provided instances

play-json type provided instances
Reads[A] Functor, Applicative, Monad
Writes[A] Contravariant
Format[A] Invariant
JsResult[A] Functor, Applicative, ApplicativeError
Monad, MonadError, Traverse,
Monoid (for A: Monoid)