diff --git a/zio-schema-json/shared/src/main/scala/zio/schema/codec/JsonCodec.scala b/zio-schema-json/shared/src/main/scala/zio/schema/codec/JsonCodec.scala index c6de56916..e2a99c621 100644 --- a/zio-schema-json/shared/src/main/scala/zio/schema/codec/JsonCodec.scala +++ b/zio-schema-json/shared/src/main/scala/zio/schema/codec/JsonCodec.scala @@ -551,10 +551,10 @@ object JsonCodec { indent_ = bump(indent) pad(indent_, out) } - left.unsafeEncode(a, indent, out) + left.unsafeEncode(a, indent_, out) out.write(',') if (doPrettyPrint) pad(indent_, out) - right.unsafeEncode(b, indent, out) + right.unsafeEncode(b, indent_, out) if (doPrettyPrint) pad(indent, out) out.write(']') } diff --git a/zio-schema-json/shared/src/test/scala/zio/schema/codec/JsonCodecSpec.scala b/zio-schema-json/shared/src/test/scala/zio/schema/codec/JsonCodecSpec.scala index 572ee55cf..06c9f391b 100644 --- a/zio-schema-json/shared/src/test/scala/zio/schema/codec/JsonCodecSpec.scala +++ b/zio-schema-json/shared/src/test/scala/zio/schema/codec/JsonCodecSpec.scala @@ -79,6 +79,27 @@ object JsonCodecSpec extends ZIOSpecDefault { Fallback.Both(3, "hello"), """[3,"hello"]""" ) + }, + test("both pretty printed") { + val json = JsonCodec + .jsonCodec(Schema.Fallback(Schema.set[Int], Schema.chunk[String])) + .encoder + .encodeJson( + Fallback.Both(Set(3), Chunk("hello")), + Some(0) + ) + assert(json)( + equalTo( + """[ + | [ + | 3 + | ], + | [ + | "hello" + | ] + |]""".stripMargin + ) + ) } ), suite("optional")(