describedby or $schema attributes

200 views
Skip to first unread message

Jean-Hugues

unread,
Oct 11, 2011, 3:21:13 AM10/11/11
to JSON Schema
Hi,

Is instance1 or instance2 the correct way to specify the schema that
an instance must validate ?

var schema = {

"id" : "http://example.com/schema-test",
"extends" : { "$ref" : "http://json-schema.org/draft-03/schema#" },

"type" : "object",
"properties" : {
"test" : {
"type" : "string",
}
}
}

var instance1 = {
'$schema' : 'http://example.com/schema-test',
'test' : 'value'
}

var instance2 = {
'links' : {"rel" : "describedby", "href": 'http://example.com/schema-
test'},
'test' : 'value'
}


regards.

Gary Court

unread,
Oct 12, 2011, 12:12:48 AM10/12/11
to json-...@googlegroups.com
Neither. The "$schema" and "links" attributes are only used on JSON
schemas, not instances.

--Gary

Gary Court

unread,
Oct 12, 2011, 12:22:28 AM10/12/11
to json-...@googlegroups.com
Sorry, I didn't read your example closely enough. Because you are
extending the draft-03 schema in the "schema" variable, then
"instance1" specifies that "schema-test" is "instance1"'s schema;
which makes "instance1" a schema itself.

--Gary

d2

unread,
Oct 19, 2011, 5:58:54 AM10/19/11
to JSON Schema
So, how to indicate the schema describing an instance in the
instance ? "instance2" is the correct way to do that ?

David

On 12 oct, 06:22, Gary Court <gary.co...@gmail.com> wrote:
> Sorry, I didn't read your example closely enough. Because you are
> extending the draft-03 schema in the "schema" variable, then
> "instance1" specifies that "schema-test" is "instance1"'s schema;
> which makes "instance1" a schema itself.
>
> --Gary
>
>
>
>
>
>
>
> On Tue, Oct 11, 2011 at 10:12 PM, Gary Court <gary.co...@gmail.com> wrote:
> > Neither. The "$schema" and "links" attributes are only used on JSON
> > schemas, not instances.
>
> > --Gary
>

Gary Court

unread,
Oct 20, 2011, 3:48:18 PM10/20/11
to JSON Schema
I think this is what you are asking for:

instance.json:

{
"$schema" : "schema.json"
}

schema.json:

{
"links" : [
{
"rel" : "describedby",
"href" : "{$schema}"
}
]
}

--Gary

Dean Landolt

unread,
Oct 21, 2011, 2:37:30 PM10/21/11
to json-...@googlegroups.com


On Thu, Oct 20, 2011 at 3:48 PM, Gary Court <gary....@gmail.com> wrote:
I think this is what you are asking for:

instance.json:

{
       "$schema" : "schema.json"
}

schema.json:

{
       "links" : [
               {
                       "rel" : "describedby",
                       "href" : "{$schema}"
               }
       ]
}


This is a circular definition though. You've got a chicken/egg problem that can only really be solved at the application level by convention.

Gary Court

unread,
Oct 21, 2011, 3:15:32 PM10/21/11
to json-...@googlegroups.com

Yes, that is correct. JSON values have no meaning until a schema is
applied to it. So when you apply this schema against the instance, you
then understand that "$schema" is a reference to the schema that
should be validating the instance. Except a parser/interpreter already
knows this, so it's just there for semantics.

--Gary

Dean Landolt

unread,
Oct 21, 2011, 3:18:13 PM10/21/11
to json-...@googlegroups.com
I thought a parser/interpreter had to be told somehow that an instance is a schema for $schema (and $ref) to be meaningful? Is that not the case?

Gary Court

unread,
Oct 21, 2011, 6:14:08 PM10/21/11
to json-...@googlegroups.com

The meaning of any property (like "$schema" and "$ref") are based from
the schema that gives those properties meaning.

--Gary

Dean Landolt

unread,
Oct 22, 2011, 11:08:40 AM10/22/11
to json-...@googlegroups.com
Sure, but an instance doesn't yet have a schema when it's using $schema to say what it's schema should be, right? This is the chicken and egg problem.

Nate Morse

unread,
Oct 22, 2011, 12:11:22 PM10/22/11
to json-...@googlegroups.com
JSON is not like XML. JSON does not have a defined way of declaring a schema that it (should) adhere to, and JSON-schema does not require any additional conventions be added to an instance, so you can put anything you want in your JSON-instance, but there is no standard way of declaring a schema in your instance.  True?
 

--
You received this message because you are subscribed to the Google Groups "JSON Schema" group.
To post to this group, send email to json-...@googlegroups.com.
To unsubscribe from this group, send email to json-schema...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/json-schema?hl=en.

Dean Landolt

unread,
Oct 22, 2011, 12:19:41 PM10/22/11
to json-...@googlegroups.com
On Sat, Oct 22, 2011 at 12:11 PM, Nate Morse <morse...@gmail.com> wrote:
JSON is not like XML. JSON does not have a defined way of declaring a schema that it (should) adhere to, and JSON-schema does not require any additional conventions be added to an instance, so you can put anything you want in your JSON-instance, but there is no standard way of declaring a schema in your instance.  True?

That's definitely true of JSON itself, but JSON + JSONSchema is a slightly different beast -- it's feasible that in the context of a JSONSchema validation the validator should always treat the $schema property as a reference to a schema unless it's already aware of an instance and that instance overrides the meaning of $schema. I don't think this is the case, but it's one possible approach that could be spec'd. I'm not convinced that introducing the notion of a default schema would be a good idea, but it definitely has it's use cases.

Dean Landolt

unread,
Oct 22, 2011, 12:20:52 PM10/22/11
to json-...@googlegroups.com
Err, that is: unless it's already aware of a schema for an instance and that schema overrides the meaning of $schema.

Nate Morse

unread,
Oct 22, 2011, 2:48:22 PM10/22/11
to json-...@googlegroups.com
thanks,  now I see the "different beast" square in the eye. 

--
Reply all
Reply to author
Forward
0 new messages