Instances with references to other objects

135 views
Skip to first unread message

Konstantin Käfer

unread,
Jun 18, 2012, 6:22:15 AM6/18/12
to json-...@googlegroups.com
Hi,

I'm trying to validate instances that contain references to other objects.

Let's say my instance is

{
    id: 4,
    billingdate: "Mon Jun 18 2012 12:19:51 GMT+0200 (CEST)",
    outbound: { "$ref": 3 }
}

According to http://www.slideshare.net/kriszyp/json-referencing-and-schema-presentation, instances can contain references to other objects. My schema specifies that "outbound" should have a certain schema. Is $ref even still valid JSON schema in instances? How can I validate an instance of the object (as above) without explicitly stating all children? I.e. the validator should just assume that the object with id 3 is of the required type.

I'm currently using JSV to validate instances against my schema.

Cheers,
Konstantin

Francis Galiegue

unread,
Jun 18, 2012, 7:52:08 AM6/18/12
to json-...@googlegroups.com
This slideshare is wrong: you cannot obtain JSON Schema instances from
an instance being validated. This is not the kind of constraint which
can be enforced by JSON Schema.

A $ref in JSON Schema is to be interpreted as a JSON Reference and its
contents unconditionally replaced with what the $ref points to (and
note that it may not even be a JSON document to begin with). But a
JSON Reference _cannot_ point to parts of the instance being validated
-- unless your instance is accessible via an absolute URI.. Should JSV
be able to do that, it would do so outside the JSON Schema spec
itself. It is not guaranteed _at all_ that it will work with any other
conforming JSON Schema implementation.

What's more, the slide you point out to also falls short in several
ways of conforming to the JSON Schema specification at all (it assumes
Javascript in too many places, JSON Schema is language independent).

In summary: can you try and formalize your problem? The solution may
(or may not) be implemented using JSON Schema proper.

--
Francis Galiegue, fgal...@gmail.com
"It seems obvious [...] that at least some 'business intelligence'
tools invest so much intelligence on the business side that they have
nothing left for generating SQL queries" (Stéphane Faroult, in "The
Art of SQL", ISBN 0-596-00894-5)

Konstantin Käfer

unread,
Jun 18, 2012, 8:20:36 AM6/18/12
to json-...@googlegroups.com
Hi,

thanks for your reply; that cleared up some things.

Basically I want to validate circular structures with JSON schema. I can write a schema that has circular references without problems, but validating it will always fail (because JSON doesn't support circular structures).

Konstantin

Francis Galiegue

unread,
Jun 18, 2012, 8:24:59 AM6/18/12
to json-...@googlegroups.com
On Mon, Jun 18, 2012 at 2:20 PM, Konstantin Käfer <kka...@gmail.com> wrote:
> Hi,
>
> thanks for your reply; that cleared up some things.
>
> Basically I want to validate circular structures with JSON schema. I can
> write a schema that has circular references without problems, but validating
> it will always fail (because JSON doesn't support circular structures).
>

JSON Schema does, however (see the self-defining JSON Schema for
instance). Can you give a concrete example?
Reply all
Reply to author
Forward
0 new messages