Search code examples
scalaplay-json

Generate Json schema from case classes (play framework)


I am using Play framework's to convert between a case class and Json.

How can I extract the schema of the Json corresponding to the case class?

Edit: If the class is case class Foo(string:Option[String], int:Option[Int])

Schema should be (approximately):

{
 "$schema": "http://json-schema.org/draft-07/schema#",
 "$id": "http://example.com/product.schema.json",
 "title": "Foo",
 "type": "object",
 "properties": {
   "string": {
     "type": "string"
   },
   "int": {
     "type": "int"
   }
 },
 "required": [ ]
}

Solution

  • Use scala-jsonschema for that and sponsor the author of this great library.

    The library supports also spray-json, circe and some other JSON parsers for Scala.