Below is a more sophisticated example, first the instance object:
{
"name" : "John Doe",
"born" : "1979-03-23T06:26:07Z",
"gender" : "male",
"address" : "object",
"properties" :
{"street":"123 S Main St",
"city":"Springfield",
"state":"CA"}
}
surely this should be
{
"name" : "John Doe",
"born" : "1979-03-23T06:26:07Z",
"gender" : "male",
"address" : {"street":"123 S Main St",
"city":"Springfield",
"state":"CA"}
}
"address" : {"type":"string",
"format":"street-address"}}
would not validate. Shouldn't it be:
"address" : {"type: "object", "format":"street-address"}or something?
Thanks, that should be fixed, the "properties" schema attribute uses the
object type definition, which is defined in the list of attributes, but it
should be included in the grammar for clarity.
> Is it supposed to be included in the following line?
> type-definition = union-type-definition | simple-type-definition
> would become:
> type-definition = union-type-definition | simple-type-definition |
> object-type-definition
The latter was the way I had it originally, but popular vote suggested the
former.
Thanks,
Kris
Or these two:
{rangeIndex:3}
and
{rangeIndex:{min:1,max:5}}
These are type unions. Unfortuneately, the first set can't be expressed with
JSON Schema, the group decided to use the simpler union syntax which only
allows for union on primitives. However the second set can be expressed with
JSON Schema because we can union on primitives:
{type:"object",
properties:{
rangeIndex:{
type:["integer","object"],
properties:{
min:{type:"integer"},
max:{type:"integer"}
}
}
}
}
This means that the rangeIndex can be an object or an integer. If it is an
object than the properties attributes applies which defines which properties
it should have.
Kris
----- Original Message -----
From: "Fox Convert" <rp31...@gmail.com>
To: "JSON Schema" <json-...@googlegroups.com>
Sent: Thursday, March 20, 2008 2:41 PM
Subject: Re: View this page "JSON Schema Proposal - second draft"
>
It would be easy to have optional regexes if we could have schemas in
union types... perhaps we should revisit that decision? This would
allow more finely grained options.
The idea of having a negation type, of saying 'any type but X' is
interesting, and quite possibly useful. This would allow disallowing
(sorry) certain regex patterns, but also other types too.
{
"type":"any",
"disallow": ["number", "string"]
}
Dave
>
> The idea of having a negation type, of saying 'any type but X' is
> interesting, and quite possibly useful. This would allow disallowing
> (sorry) certain regex patterns, but also other types too.
Good idea, that has a lot broader application than just regex. Another
application that could possibly see a lot of use:
{type:"any",
disallow:"null"}
to indicate a non-nullable value.
Great ideas, David!
Thanks,
Kris
There have been several requests that it would seem could be handled by
schema unions, and negated schemas. I propose that we should reallow schemas
in the union for the type attribute. A valid instance must still pass all
the requirements of the base schema, and when the type value is an array,
the instance value must match one of the items in the array (correct
primitive type, or match one of the schemas). Perhaps we should also add the
following attribute:
disallow - This would act the same as the "type" attribute except that if
the instance value matched the primitive type value, or any of the primitive
types or schemas in an array, than the schema is not valid
So therefore we could write:
{type:[{regex:"good"},{regex:"great"}],
disallow:[{regex:"bad"}]}
which would accept "a good one", "great string" and reject "a bad one",
"good bad".
{type:[{
disallow: {
properties: {
country:{options:[{value:"US"}]}
}
}
},
{
properties: {
state:{type:"string"}
}
}
],
properties{
country:{type:"string"}
}
}
which would allow country to be any string, but if it is equals to "US",
then the state property must be included. Not pretty but it works. Or the
more attractive use is in the succint ability to define a non-nullable
value:
I see where you're headed with this, but the second example really
throws me. It seems to disallow state if the chosen option of country
is "US", but you're saying the opposite.
Jim Norman
----- Original Message -----
From: "Jim Norman" <j...@jsnorman.net>
To: <json-...@googlegroups.com>
Sent: Sunday, April 20, 2008 9:15 PM
Subject: Re: View this page "JSON Schema Proposal - second draft"
>
----- Original Message -----From: Jim NormanSent: Thursday, April 24, 2008 4:35 PMSubject: Re: View this page "JSON Schema Proposal - second draft"
----- Original Message -----From: Jim Norman
Sent: Thursday, April 24, 2008 4:35 PMSubject: Re: View this page "JSON Schema Proposal - second draft"
Obviously that is useless.
>
> Maybe the use only for any type? Is really usefull?
Since we are once again allowing schemas in union types and disallow arrays,
you now have the ability to compose very complex logic with disallow. For
example consider this naive XML checker that doesn't allow script tags
(obviously this doesn't really handle all XML, just is an example):
{
type:"string",
pattern:"<\w+>[^<]*</\w+>",
disallow:[{pattern:"<script>"}]
}
By using disallow with schemas you can create some pretty sophisticated
rules without much burden on the validator.
Kris
> >
>
No, sorry, you can't do that. "disallow" is intended to be a direct negation
of "type", which makes it extremely easy to implement for validators. Plus
if you allowed values, you couldn't allow types because of the ambiguity.
Kris
No, I used a pattern attribute in the disallow:
{
Just a couple of comments:
1) "required" should be "requires" in the following:
*requires
*This indicates that if this property is present, the property given by
/requires /attribute must also be present. For example if a object type
definition is defined:
|{"state":{optional:true},"town":{"required":"state",optional:true}}|
2) This links are broken:
http://groups.google.com/group/json-schema/web/json-schema-possible-formats
http://groups.google.com/group/json-schema/web/common-json-schema-definitions
Jim Norman
Kris Zyp wrote:
Thanks, fixed that.
>
> 2) This links are broken:
> http://groups.google.com/group/json-schema/web/json-schema-possible-formats
> http://groups.google.com/group/json-schema/web/common-json-schema-definitions
They don't appear to be broken to me, although they were spammed way back
when, so I fixed that.
Kris
I updated the specification (working draft) to hopefully make them more
clear.
Thanks,
Kris
----- Original Message -----
From: "Steve Vinoski" <vin...@gmail.com>
To: "JSON Schema" <json-...@googlegroups.com>