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/31Thanks for the suggestion!
Jon