JSON Schema keyRef?

235 views
Skip to first unread message

Daniel Prince

unread,
Aug 20, 2013, 4:55:35 PM8/20/13
to json-...@googlegroups.com
Hello,

I just starting to look into JSON schema to replace some of the XSD's I'd got in a few applications.

Is there a function similar to a XSD Key/keyRef ? Or are the relationships expected to be validated by the application?

Thanks,

Geraint

unread,
Aug 20, 2013, 8:46:08 PM8/20/13
to json-...@googlegroups.com
The validation specification does not cover that situation.  The validation is context-free, so it is independent of the wider context of the document - you should be able to embed part or all of these documents within a larger document/collection, and still validate by just referencing the appropriate schema.

However, you can express that relationship using links (from the hyper-schema spec).  A normal "structural" validator would ignore links, but a "hyper-validator" that verifies links is perfectly possible.

Example schema:
{
    "type": "object",
    "properties": {
        "referenceableItems": {
            "type": "array",
            "items": {
                "type": "object",
                "properties": {
                    "id": {"type": "string"},
                    "name": {"type": "string"}
                },
                "links": [{
                    "href": "#{id}",
                    "rel": "self"
                }]
            }
        },
        "reference": {
            "type": "string",
            "links": [{
                "href": "#{$}",
                "rel": "full"
            }]
        }
    }
}

Example data: - annotated with links defined by the schema
{
    "referenceableItems": [
        {                             // "self" link means this item has fragment URL: #abc
            "id": "abc",
            "name": "Item A-B-C"
        },
        {                             // "self" link means this item has fragment URL: #def
            "id": "def",
            "name": "Item D-E-F"
        }
    ],
    "reference": "abc"        // has "full" link pointing to: #abc
}

So, the relationships between separate parts of the document can be described using links.  A hyper-validator could inspect the links in the document, verify that the "self" links do not clash, and verify that the target of the "full" link did in fact exist.  It even has the potential to support validation of cross-document links (if you are validating a whole set at once).

That may or may not be what you're looking for - however, I reckon it's what I would do.

Geraint

P.S. - are there any languages you're using in particular?  I suspect that "hyper-validators" are not particularly common yet.

Daniel Prince

unread,
Aug 25, 2013, 8:12:24 PM8/25/13
to json-...@googlegroups.com
Thank you!

 I'm doing additional research on the links attribute now and looks like what I need. The downside is it doesn't look like I have a hyper-validator in perl yet.

Thanks again!

Vasileios Anagnostopoulos

unread,
Feb 26, 2015, 8:16:55 AM2/26/15
to json-...@googlegroups.com
Which editor can I use to validate the example with the schema?

thanks

Sebastian Lasse

unread,
Feb 27, 2015, 3:19:46 PM2/27/15
to json-...@googlegroups.com
Daniel,

please be also aware that I am working nightly totally active on this project:

I am basically doing this to be able to import the structure and "those we can convert"-constraints of
RDFS / OWL / XSD to JSON Schema for a visual JSON schema editor I described before.

I think we also need a better way to specify that a JSON Schema has an OWL (or whatever) equivalent.
I am in favor of a sameAs meta keyword which can be specified as a mini JSON schema -
an object with 'href' and 'media'/'type' and the other meta keywords.

The focus will be first on OWL ontologies. But it should become a place to convert xsd too.
E.g. the predefined datatypes etc. are done.
The version on github currently does not cover the resolving on external links yet. I am working on this.

Any contributions are welcome !

fithi...@gmail.com

unread,
Feb 28, 2015, 5:52:56 AM2/28/15
to json-...@googlegroups.com
Theexample throws errors in

http://json-schema-validator.herokuapp.com/

It seems it cannot be validated due to syntax error in schema.
Reply all
Reply to author
Forward
0 new messages