Updated page "JSON Schema proposal - first draft"

24 views
Skip to first unread message

Kris Zyp

unread,
Jan 5, 2008, 2:01:09 PM1/5/08
to JSON Schema
I made the changes as I discussed in the last email. A few
questionable areas:
1. Should nullable be removed, since I added the type "null"? I think
so, but the only issue is whether that would make it excessively
difficult to define that a property value as being anything but null,
as you would have to use a union type:
["string","number","object","array","boolean"]. Or alternatively, the
"any" type could refer to any non-null value, and a smaller union type
could be used to indicate any value including null:
["any","null"]
2. The new property additionalProperties seems clunky. The goal is to
provide some means to define the schema type for any additional
properties. Two ways to do it, the first is with additonalProperties:
{type:{
foo:{
type:"string"}},
additionalProperties:{
type:"string"}}
Second is the original way with the "*" property:
{type:{
foo:{
type:"string"},
"*":{
type:"string"}}
}
This would able to validate something like:
{foo:"bar",otherProp:"some string"}
I think the "*" is more readable, but it does have name clash
possibility (if one wanted to validate an instance property "*").

Matt (MPCM)

unread,
Jan 5, 2008, 9:26:44 PM1/5/08
to JSON Schema
Addressing #1, often we expect a type (perhaps a few types). Or we
expect any type and do our own handling after the schema matching.

Perhaps it is the type of systems I deal with, but rarely would I use
"anything, but not null". I think removing nullable and requiring a
union type is clearer. For that reason I would not muddy the waters by
assigning special meaning to "any".

"any" should include all types. I would rather see "!<type>" excluding
prefixes, before making "any" not mean any.

Have those who need such a broad but selectively exclusive need use
["string","number","object","array","boolean"]. It is simple and
follows logical rules without exception.

Kris Zyp

unread,
Jan 5, 2008, 10:48:17 PM1/5/08
to json-...@googlegroups.com
Thanks, sounds good to me. I edited the proposal per your suggestion.
Kris

Claudio D'Angelo

unread,
Jan 6, 2008, 4:24:18 AM1/6/08
to JSON Schema
nillable must continue to exist.
The scope of nillable is that an attribute with a specific type CAN be
null.
The type null is used to indicate that the attribute MUST be null.

Matt (MPCM)

unread,
Jan 6, 2008, 9:08:56 AM1/6/08
to JSON Schema
Wouldn't a union type cover this?

Kris Zyp

unread,
Jan 6, 2008, 11:43:33 AM1/6/08
to json-...@googlegroups.com
Yes, any type definition can be unioned with "null" so as to support
optional nulls. For example ["string","null"] is a nullable string. Claudio,
is the problem that you don't currently support union types?

Kris
----- Original Message -----
From: "Matt (MPCM)" <Wicke...@gmail.com>
To: "JSON Schema" <json-...@googlegroups.com>

Claudio D'Angelo

unread,
Jan 7, 2008, 2:48:55 AM1/7/08
to JSON Schema
The union can't be used in all system. In typed language you can't
manage an attribute that can be a string or integer or date.

This methodology can go well for javascript but not for java or C++.

Claudio D'Angelo

unread,
Jan 7, 2008, 2:48:55 AM1/7/08
to JSON Schema
The union can't be used in all system. In typed language you can't
manage an attribute that can be a string or integer or date.

This methodology can go well for javascript but not for java or C++.


On 6 Gen, 17:43, "Kris Zyp" <kris...@gmail.com> wrote:

Kris Zyp

unread,
Jan 7, 2008, 10:20:58 AM1/7/08
to json-...@googlegroups.com
JS1/ES3 doesn't have support for union types either. That doesn't mean you
can use the validator to validate instances. You just can't have exact
correspondence of type constraints in the generated classes. Java classes
can certainly approximate JSON Schemas much more accurately than JavaScript
because JS1/ES3 doesn't have types. There is certainly no requirement that
you have to an exact correspondence though, generated classes that may be
populated with JSON instance simply must have a type that is at least as
wide the JSON Schema type. With allowance for primitive wrappers Java always
has a type that is at least as wide as a JSON Schema type. In Java, an
Object type is wide enough to handle a String, Integer, or Date.

Claudio D'angelo

unread,
Jan 7, 2008, 10:54:47 AM1/7/08
to json-...@googlegroups.com
Too many confusion... For my system schema must be a type and format
validator.
I can't encourage the use of Object because It's can cause
ClassCastException or useless prolongation of code.

The schema serve to my system to speak the same language with other
systems. In an example:
|"born" : {"type":["integer","string"], /allow for a numeric year, or a
full date/
"format":"date", /format when a string value is used/
"minimum":1900, /min/max for when a numberic value is used
/|| "maximum":2010,
"optional":true
},
this step indicate that I can receive a date object (with all
informations) or an integer (with year).

Introduce the union only to manage a nullable attribute involve to
manage other information (if then else statements) during the validation.

For my system json schema is became too much expensive.

I think that I must search another method to validate.
|

Kris Zyp ha scritto:

Kris Zyp

unread,
Jan 7, 2008, 11:20:20 AM1/7/08
to json-...@googlegroups.com
> Too many confusion... For my system schema must be a type and format
> validator.

I really don't think you should necessarily be doing format validation,
especially if you are concerned about the complexity/expense of the system.
Of course, JSON Schema is a form of documentation to establish correctness,
and documentation exists at various levels of complexity. There is minimal
level correctness that can it is dictated by types, and there is higher
level of correctness (reasonable data) that can only be discerned from
descriptions. "format" falls in between, and in addition is probably the
most likely area of JSON Schema to change/evolve. It is naive to assume that
you can have just one level of bound of correctness, and that will solve all
correctness problems. Documentation like JSON Schema can and should be
progressive in it's ability to describe acceptable data.

> I can't encourage the use of Object because It's can cause
> ClassCastException or useless prolongation of code.

How then would you describe a property that can have an integer or string? I
would assume that without union types, you would have to use "any", which
presumably you would translate to the Java type Object, and you would be
back to where you started, except the Schema would be less descriptive, have
a lower level of validation capability and provide less information for
languages that do support union types.
Kris

Claudio D'angelo

unread,
Jan 8, 2008, 2:28:46 AM1/8/08
to json-...@googlegroups.com
Sorry Kris,
yesterday was a bad day. I've slept up and I think that it isn't a problem.

For me is OK (although I think that the property nillable is more readable).

Kris Zyp ha scritto:

Claudio D'Angelo

unread,
Jan 8, 2008, 3:33:48 AM1/8/08
to JSON Schema
Can anybody send me an example of addtionalProperties and what checks
must be done?

Claudio D'Angelo

unread,
Jan 8, 2008, 4:50:37 AM1/8/08
to JSON Schema
Is this property element valid?

"myDate" : {
"type" : [
{ "type" : "string",
"format" : "date"},
{"type" : "string",
"pattern" : "[0-9][0-9][0-9][0-9]" },
"number" ]
...

Claudio D'Angelo

unread,
Jan 8, 2008, 5:35:58 AM1/8/08
to JSON Schema
What about name collision?

Claudio D'Angelo

unread,
Jan 8, 2008, 5:38:42 AM1/8/08
to JSON Schema
For a json stream that must start with array how can I use the schema
location?

Claudio D'Angelo

unread,
Jan 8, 2008, 6:02:48 AM1/8/08
to JSON Schema
what do you think if the name of the attributes starts with a prefix?
Example :
{ "type" : {
"js:name" : {"type" : "string"},
"js:age" : {"type" : "number"}
}}
or
{ "type" : {
"${name}" : {"type" : "string"},
"${age}" : {"type" : "number"}
}}

Kris Zyp

unread,
Jan 8, 2008, 9:25:05 AM1/8/08
to json-...@googlegroups.com
No, a type attribute or union type members require type definitions, and you
can't use a property definition (like {"type":"string"}) in a place that
requires a type definition (like "string"). Therefore you would have to
write:
"myDate" : {

"type" : ["string","number"],
"format" : "date",
"pattern":"([0-9][0-9][0-9][0-9])|(...your date regex...)"
}

Kris

Kris Zyp

unread,
Jan 8, 2008, 9:28:07 AM1/8/08
to json-...@googlegroups.com
There is no posssibility of name collisions because all the JSON Schema
properties are now defined on a property definition, and an instance
properties (your properties) definitions are all defined on the object type
definitions. The exception would be if we reintroduced "*" as property in
object type properties to define all properties not explicitly defined, then
we could have a collision with "*".
My hope was this would make life drastically simpler for you, because you
would not need namespaces anymore.

Kris
----- Original Message -----
From: "Claudio D'Angelo" <claudio...@lombardia-servizi.it>
To: "JSON Schema" <json-...@googlegroups.com>
Sent: Tuesday, January 08, 2008 3:35 AM
Subject: Discussion on json-schema-proposal---first-draft


>
> What about name collision?
> >
>

Kris Zyp

unread,
Jan 8, 2008, 9:30:08 AM1/8/08
to json-...@googlegroups.com
Great question, I am not sure. Any suggestions? In previous work I have
sometimes used a convention of having a special array property that can
point to an array that indicates that the array and parent key values should
be mixed in. I don't really want to pollute JSON Schema with that though.

Kris
----- Original Message -----
From: "Claudio D'Angelo" <claudio...@lombardia-servizi.it>
To: "JSON Schema" <json-...@googlegroups.com>
Sent: Tuesday, January 08, 2008 3:38 AM
Subject: Discussion on json-schema-proposal---first-draft


>

Kris Zyp

unread,
Jan 8, 2008, 9:34:13 AM1/8/08
to json-...@googlegroups.com
I understand, and sorry JSON Schema is still changing so much, but I think
we are really making progress, and that we are getting close to a really
good spec. Thank you so much for your help, obviously your suggestions and
advice from implementation have been critical in moving this forward.
Thanks,

Kris
----- Original Message -----
From: "Claudio D'angelo" <claudio...@lombardia-servizi.it>
To: <json-...@googlegroups.com>
Sent: Tuesday, January 08, 2008 12:28 AM
Subject: Re: Discussione su json-schema-proposal---first-draft


>

Claudio D'angelo

unread,
Jan 8, 2008, 9:39:40 AM1/8/08
to json-...@googlegroups.com
ok
and i can use type object in union?

"type" : [
{
"name" : {"type" : "string"...},
"surname" : {...},
...
},
{
"enterpriceName" : {...},
...
}
],


Kris Zyp ha scritto:

Claudio D'angelo

unread,
Jan 8, 2008, 9:40:26 AM1/8/08
to json-...@googlegroups.com
and the final attribute?

Kris Zyp ha scritto:

Claudio D'Angelo

unread,
Jan 8, 2008, 10:02:10 AM1/8/08
to JSON Schema
Is possible change the the schema location attribute with another name
that avoid attribute 's confict?
For example $schema or $json:schema.

Kris Zyp

unread,
Jan 8, 2008, 10:23:01 AM1/8/08
to json-...@googlegroups.com
Yes, and the "final" attribute is now in the property definition (peer to
type, minimum, maximum, etc.).

Kris
----- Original Message -----

Kris Zyp

unread,
Jan 8, 2008, 10:24:46 AM1/8/08
to json-...@googlegroups.com
Yes, you can use the "type object" (object type definition) in a union.

Kris
----- Original Message -----
From: "Claudio D'angelo" <claudio...@lombardia-servizi.it>
To: <json-...@googlegroups.com>
Sent: Tuesday, January 08, 2008 7:39 AM
Subject: Re: Discussion on json-schema-proposal---first-draft


>

Claudio D'angelo

unread,
Jan 8, 2008, 10:34:22 AM1/8/08
to json-...@googlegroups.com
Perfect...
in the object declaration there are only the attribute names, isn't it?


Kris Zyp ha scritto:

Kris Zyp

unread,
Jan 8, 2008, 10:42:23 AM1/8/08
to json-...@googlegroups.com
Yes, only the names of properties in the instance object that will be
validated, no JSON Schema defined properties (like type, minimum, etc.)

Claudio D'Angelo

unread,
Jan 8, 2008, 10:58:18 AM1/8/08
to JSON Schema
How can I tell that an attribute that is an array can be null?
The expression
"type" : ["null", ["string", "integer"]]
is a vaid format to indicate an array that contains both string and
integer and can be null?

Kris Zyp

unread,
Jan 8, 2008, 11:10:33 AM1/8/08
to json-...@googlegroups.com
Close, it is:

"type" : ["null", [["string", "integer"]]
You have to [] with a single item to indicate an array, otherwise, it is
just a nested union type. ["null",["string","integer"]] =
["null","string","integer"]
By putting [] around the ["string","integer"] you will indicate that it is
an array of that type.
Note that the main reason to use the "null" type instead of the "nullable"
attribute is that it would be impossible to denote an array of values, where
each value could be a string or null. With the null type you can do it with
[["string","null"]].
Kris


----- Original Message -----
From: "Claudio D'Angelo" <claudio...@lombardia-servizi.it>
To: "JSON Schema" <json-...@googlegroups.com>
Sent: Tuesday, January 08, 2008 8:58 AM
Subject: Discussion on json-schema-proposal---first-draft


>

Kris Zyp

unread,
Jan 8, 2008, 11:17:39 AM1/8/08
to json-...@googlegroups.com
Ok, here is an example schema:
{"type":{"foo":{"type":"string"}},
"additionalProperties":{"type":"number"}
}
This would indicate that the target instance must be an object with a foo
property with a string value, and any other properties must have a number
value. So the following would validate:
{"foo":"bar","otherProp":1,"anotherProp":2,"yetAnotherProp":3}
And this would not validate:
{"foo":"bar","otherProp":"a string value","anotherProp":true}

I still think that using "*" would make a more readable equivalent schema:
{"type":{"foo":{"type":"string"},
"*":{"type":"number"}}
}
But it does introduce a name clash, and it is worth noting that a parallel
situation exists in the SMD (service mapping definition) with parameters,
and I would like to keep them in sync (SMD has an additionalParameters
property). Change both, or neither...
Kris

----- Original Message -----
From: "Claudio D'Angelo" <claudio...@lombardia-servizi.it>
To: "JSON Schema" <json-...@googlegroups.com>
Sent: Tuesday, January 08, 2008 1:33 AM
Subject: Discussion on json-schema-proposal---first-draft


>

Kris Zyp

unread,
Jan 8, 2008, 11:18:55 AM1/8/08
to json-...@googlegroups.com


>

Kris Zyp

unread,
Jan 8, 2008, 11:20:11 AM1/8/08
to json-...@googlegroups.com


>

Claudio D'angelo

unread,
Jan 9, 2008, 2:28:57 AM1/9/08
to json-...@googlegroups.com
You wrote

["null",["string","integer"]] = ["null","string","integer"]
but
I'm not agree ... ["null","string","integer"] indicate that an array can contain a string, an integer or a null.
I want indicate that an attribute is an array of string or integer but this attribute can be null

Kris Zyp ha scritto:

Claudio D'Angelo

unread,
Jan 9, 2008, 3:00:52 AM1/9/08
to JSON Schema
Is possible add a schema reference properties for object type?
This is useful if I have a schema that represents an object and in
another schema I represents an array of the above object:
--schema1.json
{type : {...}}

--schema2.json
{type: [{type:{}, $schema : "uri of schema1.json"}]}

Claudio D'angelo

unread,
Jan 9, 2008, 3:01:42 AM1/9/08
to json-...@googlegroups.com
Sorry Kris I don't have read correctly.
Don't take my response in consideration

Kris Zyp ha scritto:

Claudio D'Angelo

unread,
Jan 9, 2008, 4:09:13 AM1/9/08
to JSON Schema
Hi,
this schema:
"myattr" : {
type : ["integer", "float"],
minimum : 3,
maximum : 10,
maxDecimal : 2
}

Is valid? or this must be considered only float?

Claudio D'Angelo

unread,
Jan 9, 2008, 4:19:32 AM1/9/08
to JSON Schema
Is convenient use "number" how type and format with "integre" and
"float"?
In this manner you have that type represents only the type of json
(object, array, number, boolean, null, string and union how special
type) and format represents the format of these type

On Jan 9, 10:09 am, "Claudio D'Angelo" <claudio.dang...@lombardia-

Kris Zyp

unread,
Jan 9, 2008, 9:02:12 AM1/9/08
to json-...@googlegroups.com
A reasonable suggestion, would you prefer that?

Kris
----- Original Message -----
From: "Claudio D'Angelo" <claudio...@lombardia-servizi.it>
To: "JSON Schema" <json-...@googlegroups.com>
Sent: Wednesday, January 09, 2008 2:19 AM
Subject: Re: Discussion on json-schema-proposal---first-draft


>

Kris Zyp

unread,
Jan 9, 2008, 9:03:33 AM1/9/08
to json-...@googlegroups.com
Right now, "number" is a superset of "integer", so your schema is valid, but
redundant (no need to declare integer, since it is subset of "number").
However, if we use your other suggestion (make "integer" a format), that
would change that.

Kris
----- Original Message -----
From: "Claudio D'Angelo" <claudio...@lombardia-servizi.it>
To: "JSON Schema" <json-...@googlegroups.com>
Sent: Wednesday, January 09, 2008 2:09 AM
Subject: Discussion on json-schema-proposal---first-draft


>

Kris Zyp

unread,
Jan 9, 2008, 10:00:49 AM1/9/08
to json-...@googlegroups.com
> Is possible add a schema reference properties for object type?
> This is useful if I have a schema that represents an object and in
> another schema I represents an array of the above object:

Referencing and reusing other schemas is certainly one of my primary hopes
and goals for JSON Schema, I think it is central to the ultimate optimal use
of JSON Schema. However, referencing is also not specific to JSON Schema.
Many other forms of JSON stand to benefit from referencing capabilities, and
I don't believe it would be advantageous for JSON Schema to have it's own
referencing convention in contrast to other forms of JSON. One should be
able to use one referencing mechanism and apply it to JSON Schema as well as
other JSON. Therefore, I believe that JSON Schema should lean on another
standard/specification for referencing.
I believe that a standard for JSON referencing would be immensely valuable,
and I have put forth efforts to that end
(http://www.json.com/category/referencing/), albiet without a great deal of
success.
In the spec, I suggested the use of the JSON referencing proposal that I set
forth here:
http://www.json.com/2007/10/19/json-referencing-proposal-and-library/
which was my attempt to put together the best ideas and techniques of the
various referencing techniques that have been used and suggest a compromise
of conventions. With this proposal, one could achieve reuse of schemas by
referencing, and you could create your second schema that references the
first one like:
--schema2.json
{type: [{myProp:{$ref:"schema1.json"}}]}
Although, in this case, it might be more useful to reference the object type
definition than the schema itself.
There are also a number of examples of referencing type definitions in the
common JSON Schema definitions, in the card and calendar schemas:
http://groups.google.com/group/json-schema/web/common-json-schema-definitions
Kris

Claudio D'angelo

unread,
Jan 9, 2008, 11:02:26 AM1/9/08
to json-...@googlegroups.com
I'll implement JSPON in next step (json schema supply me more problem at
the moment). However JSPON references element in the same stream and not
in another stream.
json schema is a json stream and using JSPON with

{type: [{myProp:{$ref:"schema1.json"}}]}

will be parsed how " link another object that has myProp = "schema1.json".

I think that is useful another methodology.

Kris Zyp ha scritto:

Claudio D'angelo

unread,
Jan 11, 2008, 5:31:56 AM1/11/08
to json-...@googlegroups.com
What about the type number?

Kris Zyp ha scritto:

Claudio D'Angelo

unread,
Jan 11, 2008, 5:02:43 PM1/11/08
to JSON Schema
KRis,
I see that you have renamed the float in number. Why don't you remove
the integer type? This type can be resolved or setting maxDecimal=0 or
setting format=int[eger].
At heart integer derive from number.

On 11 Gen, 11:31, Claudio D'angelo <claudio.dang...@lombardia-
> >> Is valid? or this must be considered only float?- Nascondi testo tra virgolette -
>
> - Mostra testo tra virgolette -

Kris Zyp

unread,
Jan 12, 2008, 12:03:58 AM1/12/08
to json-...@googlegroups.com
That is a good idea. I think there are some remaining questions about how to
divide up types, that might be good to get more input.
Kris

----- Original Message -----
From: "Claudio D'Angelo" <claudio...@lombardia-servizi.it>
To: "JSON Schema" <json-...@googlegroups.com>

Sent: Friday, January 11, 2008 3:02 PM
Subject: Re: Discussion on json-schema-proposal---first-draft

David Waite

unread,
Jan 23, 2008, 1:20:40 AM1/23/08
to JSON Schema
Instead of specificity, why not have a property 'requires' which can
reference one or more names (string or array of strings) at the same
level?

This would allow you have multiple sets, and also indicate that (for
your example) both state and town have to be specified if either is
used, by having them reference one another.

Jakob Kruse

unread,
Jan 23, 2008, 11:01:00 AM1/23/08
to JSON Schema
Kris,

I find this choice rather questionable. The possible values of the
"type" defintion should be just that - types. "null" is not a type,
it's a value. Including "null" as a possible "type" value is just
starting down a slope where "true" and "false" come next (in JSON
specs they are treated the same), and that's just plain wrong.

Let's reserve "type" for types. "any" being the only reasonable
exception, because it just saves a lot of space and increases
readability.

I vote for reintroducing "nullable" (if that's what it was called - I
don't like "nillable" because the value is not "nil") as the way of
indicating that the property in question could be null. "any" would
then mean "any valid type", but not "null" unless "nullable" is true.

/Jakob


On Jan 6, 5:43 pm, "Kris Zyp" <kris...@gmail.com> wrote:
> Yes, any type definition can be unioned with "null" so as to support
> optional nulls. For example ["string","null"] is a nullable string. Claudio,
> is the problem that you don't currently support union types?
> Kris
>
> ----- Original Message -----
> From: "Matt (MPCM)" <WickedLo...@gmail.com>
> To: "JSON Schema" <json-...@googlegroups.com>
> Sent: Sunday, January 06, 2008 7:08 AM
> Subject: Re: Discussione su json-schema-proposal---first-draft
>
> > Wouldn't a union type cover this?

David Wilhelm

unread,
Jan 23, 2008, 11:40:45 AM1/23/08
to JSON Schema
I think it is useful to treat null as a type, as it doesn't belong to
any other type, but it is a valid JSON value.

On this topic, I noticed that when I attempt to validate the object:
{
"foo":null
}
with the schema:
{
"foo":{
"type":"null"
}
}
I'm still getting the error:
foo
is non-nullable, but has a null value

"type":"any" , "type":["any"] , or even "type":["any","null"]

don't seem to work either. Sorry if this is not the place for
implementation discussion. If not, where?

Cheers,
Dave

Matt (MPCM)

unread,
Jan 23, 2008, 11:52:35 AM1/23/08
to JSON Schema
"JavaScript contains a small set of data types. It has the three
primitive types boolean, number, and string and the special values
null and undefined. Everything else is variations on the object type."
- http://javascript.crockford.com/survey.html

"Vars are not typed. A var can contain a reference to an object, or a
string or a number or a boolean or null or undefined." -
http://javascript.crockford.com/survey.html

A var, which is a string, being set to null in Javascript identifies
it as an 'object' type. This is mostly recognized as being incorrect,
but that is the way it is. From my view this does make null somewhat
of a type in Javascript conceptually. I cannot take a var that is now
null and infer that it is was a string. Not sure how this shapes up in
ES4...

--
Matt
Reply all
Reply to author
Forward
0 new messages