zio-json icon indicating copy to clipboard operation
zio-json copied to clipboard

Add methods to JSON AST

Open jdegoes opened this issue 5 years ago • 1 comments

  • [ ] final def transformAt[A <: Json](cursor: JsonCursor[_, A])(f: A => Json): Either[String, Json] = ???
  • [ ] final def delete(cursor: JsonCursor[_, _]): Either[String, Json] = ???
  • [ ] final def diff(that: Json): JsonDiff = JsonDiff(self, that)
  • [ ] final def intersect(that: Json): Either[String, Json] = ???
  • [ ] final def relocate(from: JsonCursor[_, _], to: JsonCursor[_, _]): Either[String, Json] = ???

jdegoes avatar Sep 24 '20 12:09 jdegoes

I think that the most common pattern of using Json AST directly is something like :

  given JsonDecoder[ApiTransaction] = JsonDecoder[Json].map { json =>
    val c = json.cursor // somehow perform multiple ops on the cursor like this
    for {
      id         <- c.downField("id").as[TxId]
      inputs     <- c.downField("inputs").as[ArraySeq[ApiInput]]
      dataInputs <- c.downField("dataInputs").as[List[ApiDataInput]]
      outputs    <- c.downField("outputs").as[ArraySeq[ApiOutput]]
      size       <- c.downField("size").as[Int]
    } yield ApiTransaction(id, inputs, dataInputs, outputs, size)

Which is currently quite hard to put together and probably even inefficient.

pragmaxim avatar Jul 22 '23 07:07 pragmaxim