# Automatically generating tapir codecs using zio json codecs

**URL:** <https://softwaremill.community/t/automatically-generating-tapir-codecs-using-zio-json-codecs/470>\
**Category:** tapir\
**Created:** [January 26, 2025, 8:24pm UTC](https://softwaremill.community/t/automatically-generating-tapir-codecs-using-zio-json-codecs/470 "2025-01-26T20:24:29Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![mlangsenkamp](https://avatars.discourse-cdn.com/v4/letter/m/eada6e/32.png) [@mlangsenkamp](https://softwaremill.community/u/mlangsenkamp)\
**Post date:** [January 26, 2025, 8:24pm UTC](https://softwaremill.community/t/automatically-generating-tapir-codecs-using-zio-json-codecs/470/1 "2025-01-26T20:24:29Z")

</div>

I am trying to define the following endpoint:

```auto
object WebApiEndpoints {
  val geminiMarketData = endpoint.get
    .in("ws")
    .out(
      webSocketBody[
        String,
        CodecFormat.TextPlain,
        MarketDataResponse,
        CodecFormat.Json
      ](ZioStreams)
    )
}

```

I already have the zio json codecs in scope

```auto
given MarketDataResponseCodec: JsonCodec[MarketDataResponse] =
    DeriveJsonCodec
      .gen[MarketDataResponse]

```

and am getting an error asking for a

```auto
ttp.tapir.Codec[
    Array[Byte],
    MarketDataResponse,
    sttp.tapir.CodecFormat.Json
  ]

```

However I cannot find an example in the documentation on how to derive this type automatically. I am seeing some reference to creating a schema but I am not sure how that relates when I already have the zio json codec.

I would like to avoid creating the codec manually if at all possible

---

<div class="post-metadata">

**Author:** ![adamw](https://dub1.discourse-cdn.com/flex005/user_avatar/softwaremill.community/adamw/32/28_2.png) [@adamw](https://softwaremill.community/u/adamw)\
**Post date:** [January 27, 2025, 7:59am UTC](https://softwaremill.community/t/automatically-generating-tapir-codecs-using-zio-json-codecs/470/2 "2025-01-27T07:59:05Z")

</div>

Hello!

I added an example of a WS endpoint accepting and producing WS messages:

> <https://github.com/softwaremill/tapir/blob/master/examples/src/main/scala/sttp/tapir/examples/websocket/WebSocketZioHttpJsonServer.scala#L24>

It should be sufficient to import the Tapir `Codec`s for ZIO JSON, using `import sttp.tapir.json.zio.*`. Using this and the built-in implicits, a codec using them should be automatically built for `WebSocketFrame`s: [tapir/core/src/main/scala/sttp/tapir/Codec.scala at master · softwaremill/tapir · GitHub](https://github.com/softwaremill/tapir/blob/master/core/src/main/scala/sttp/tapir/Codec.scala#L402)
