zio / zio-json

Fast, secure JSON library with tight ZIO integration.
https://zio.dev/zio-json
Apache License 2.0
410 stars 147 forks source link

Add methods to JSON AST #53

Open jdegoes opened 4 years ago

jdegoes commented 4 years ago
pragmaxim commented 1 year ago

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.