anthropic4s
GitHub

Reference Structured data

PlaySchema

Builds a Schema from a Play JSON Format, from the anthropic4s-play-json module.

Reference#

PlaySchema.derived[A]#

play-json · PlaySchemaDerivation.scala
def derived[A](implicit format: Format[A]): Schema[A]

The structure is derived from the type; reading and writing go through your Format.

Caveats

Helpers#

play-json · PlaySchema.scala
def from[A](structure: Schema[A])(implicit format: Format[A]): Schema[A]
def enumFormat[A](values: (String, A)*): Format[A]
def decoder[A](implicit reads: Reads[A]): Decoder[A]
def encoder[A](implicit writes: Writes[A]): Encoder[A]
def toCirce(value: JsValue): CirceJson
def toPlay(value: CirceJson): JsValue

PlaySchema.configuration#

play-json · PlaySchema.scala
val configuration: JsonConfiguration.Aux[Json.MacroOptions]

The Play JSON configuration that matches the derived schemas: a type discriminator with short class names, and None written as null.

Usage#

From a Format#

play-json · PlaySchema.scala
object Book {
  implicit val config: JsonConfiguration = PlaySchema.configuration
  implicit val format: OFormat[Book]     = Json.format[Book]
  implicit val schema: Schema[Book]      = PlaySchema.derived[Book]
}

client.messages.parse[Book](request)

Using anthropic4s from Play shows it in a controller.

Every signature and example on this page is copied, character for character, from the public source of anthropic4s and its Scaladoc. The complete API, every type included, is in the Scaladoc of each module.