In the interest of avoiding key collisions, I think that JSON Schema
should implement namespaces (keyspaces?). The obvious problem with
this idea is that there has been a JSON namespace proposal (at least
not that I could find). so I decided to take a crack at it.
The first thing needed is a means to associate prefixes and
namespaces:
{
"name" : "
http://json-schema.org/",
"prefixes" : [ "jsd" ],
"schema" : "
http://jsonschema.googlecode.com/files/
schemaForSchema.json"
}
The (required) "name" key is self-explanitory. It's what designates
the namespace name. I'd recommend that the namespace name be limited
to absolute URIs. The (required) "prefixes" key is set to an array
that has at least one value. The values may be either strings or a
null (which would indicate the default namespace). The (optional)
"schema" key would specify the location of the schema document against
which the properties of this namespace can be validated against.
For multiple namespaces, I figured that multiple namespace objects
could be grouped together in an array, like so:
[
{
"name" : "
http://json-schema.org/",
"prefixes" : [ "jsd" ],
"schema" : "
http://jsonschema.googlecode.com/files/
schemaForSchema.json"
},
{
"name" : "
http://somedomain.com/persons",
"prefixes" : [ null, "pers" ]
}
]
and in any given object, this array is set to the key "json:ns" where
the prefix "json" is reserved and implicitly associated with a
specific URI (yet to be determined), and the local key "ns" is
reserved within the "json" namespace and may be set to a single
namespace object or an array containing namespace objects. (As a side
note, other reserved keys in the "json" namespace would include "id",
"lang", and maybe "base".)
If this were applied to the first JSON Schema example in the JSON
Schema Proposal (
http://json-schema.org/), we would get:
{
"json:ns" :
[
{
"name" : "
http://json-schema.org/",
"prefixes" : [ "jsd" ],
"schema" : "
http://jsonschema.googlecode.com/files/
schemaForSchema.json"
},
{
"name" : "
http://somedomain.com/persons",
"prefixes" : [ null, "pers" ]
}
],
"jsd:description" : "A person",
"jsd:type" : "object",
"jsd:properties" : {
"name" : { "jsd:type" : "string" },
"born" : {
"jsd:type" : [ "integer" , "string" ],
"jsd:minimum" : 1900,
"jsd:maximum" : 2010,
"jsd:format" : "date-time",
"jsd:optional" : true
}
"gender" : {
"jsd:type" : "string",
"jsd:options" : [
{ "value" : "male", "label" : "Guy" },
{ "value" : "female", "label" : "Gal" }
]
},
"address" : {
"jsd:type" : "object",
"jsd:properties" : {
"street" : { "jsd:type" : "string" },
"city" : { "jsd:type" : "string" },
"state": { "jsd:type" : "string" }
}
}
}
}
Sledge