Skip to content

iravid/play-json-cats

master
Switch branches/tags

Name already in use

A tag already exists with the provided branch name. Many Git commands accept both tag and branch names, so creating this branch may cause unexpected behavior. Are you sure you want to create this branch?
Code

Latest commit

 

Git stats

Files

Permalink
Failed to load latest commit information.
Type
Name
Latest commit message
Commit time
 
 
src
 
 
 
 
 
 
 
 
 
 
 
 

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)