aparo / zio-json-extra   0.6.2

Apache License 2.0 GitHub

Several extensions to ZIO-Json to speed up migration of projects from Circe to ZIO-Json

Scala versions: 3.x 2.13 2.12
Scala.js versions: 1.x


This is a collection of extensions to zio-json, very opionated, required to fast migrate circe code to zio-json (mainly zio-elasticsearch).

It generally targets some functionalities that are missing in zio-json such as:

  • Derivation of Enumeration in string
  • Help methods to manipulate JSON AST

There are three modules:

  • zio-json-extra that extends zio-json
  • zio-json-diffson (WIP) that provides diffson support (A scala diff/patch library for Json)
  • zio-json-exception that extends Exception managements with classes that can be module-scoped and easy "wireable".

Derivation Enumeration in String

This capability adds DeriveJsonDecoderEnum/DeriveJsonEncoderEnum that provides enum support based on plain trait/objects

  sealed trait Status extends EnumUpperCase
  case object Running extends Status
  case object Failure extends Status

  case class Entity(name: String, status: Status)

  implicit val statusDecoder: JsonDecoder[Status] = DeriveJsonDecoderEnum.gen[Status]
  implicit val statusEncoder: JsonEncoder[Status] = DeriveJsonEncoderEnum.gen[Status]
  implicit val entityDecoder: JsonDecoder[Entity] = DeriveJsonDecoder.gen[Entity]
  implicit val entityEncoder: JsonEncoder[Entity] = DeriveJsonEncoder.gen[Entity]

   # sample 

    test("simple enum upper value") {
      import exampleupperenums._
    test("case class with enum upper value") {
      import exampleupperenums._
        isRight(equalTo(Entity(name = "Sample", status = Failure)))

More example in tests