json schema validator

15 views
Skip to first unread message

workingdog

unread,
Dec 16, 2014, 2:58:57 AM12/16/14
to raptur...@googlegroups.com
Although I'm new to Rapture I think its a great set of libraries.
Is there, or will there be a json schema validator as part of the library set, something like the pure java at: https://github.com/fge/json-schema-validator




Jon Pretty

unread,
Dec 16, 2014, 4:00:52 AM12/16/14
to raptur...@googlegroups.com
Hi,

I haven't done any work on JSON Schema yet (I think that what we've already got provides a pretty comprehensive set of tools for schema-like tasks) but it's an interesting idea. Currently the closest thing is being able to define a structure of nested case classes, and extract them in one go.

What I'd like to do with JSON Schema is be able to define a JSON Schema type which could then be used to extract structured data from a `Json` value. Here's how it might look, using the example schema from http://json-schema.org/examples.html:

  val schema = jsonSchema"""{
    "title": "Example Schema",
    "type": "object",
    "properties": {
      "firstName": { "type": "string" },
      "lastName": { "type": "string" },
      "age": {
        "description": "Age in years",
        "type": "integer",
        "minimum": 0
      }
    },
    "required": ["firstName", "lastName"]
  }"""

  val j = json"""{ "firstName": "Jon", "lastName": "Pretty" }"""

  val v = j.as[schema.Type]
  val name: String = v.firstName+v.lastName
  val age: Option[Int] = v.age

  val x = v.somethingElse // Won't compile; doesn't exist

This will probably take a fair amount of work to implement, as it will need a whitebox macro to create a type representing the schema. But I've created an issue as an aide memoire here:

  https://github.com/propensive/rapture-json/issues/31

Thanks for the suggestion!
Jon


On 16 December 2014 at 07:58, workingdog <ringow...@gmail.com> wrote:
Although I'm new to Rapture I think its a great set of libraries.
Is there, or will there be a json schema validator as part of the library set, something like the pure java at: https://github.com/fge/json-schema-validator




--
You received this message because you are subscribed to the Google Groups "Rapture users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to rapture-user...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


--
Jon Pretty | @propensive
Reply all
Reply to author
Forward
0 new messages