I found a theme:
http://groups.google.com/group/json-schema/browse_thread/thread/b9dcd08b18cbad18
There is one piece of code.
{
"type": [
{
"properties": {
{ "name": "town" },
{ "name": "state" }
}
},
{
"properties": {
{ "name": "state", "optional": "true" }
}
}
]
}
So, I tried this:
s1 = {
"type": [
{
"properties": {
"qwe":{ "type":"string" },
"asd":{ "type":"string", "optional":true }
}
},
{
"properties": {
"zxc":{ "type":"string" }
}
}
]
}
e1 = {"qwe":"sssss","asd":"sss"}
e2 = {"zxc":"ssss", "qwe":"sssss","asd":"sss"}
e3 = {"any":"sssss","other":"sss", "object":"sssss"}
e4 = {"zxc":"ssss", "asd":"sss"}
//JSV.validate(e1, s1).errors.length // 0
//JSV.validate(e2, s1).errors.length // 0!
//JSV.validate(e3, s1).errors.length // 1
//JSV.validate(e4, s1).errors.length // 0!
//JSONSchema.validate(e1, s1).errors.length // 0
//JSONSchema.validate(e2, s1).errors.length // 0!
//JSONSchema.validate(e3, s1).errors.length // 1
//JSONSchema.validate(e4, s1).errors.length // 0!
Second and fourth example gave unexpected result. Was it conceived
from the outset?
Chrome has the function:
keys = function (o) { var a = []; for (var k in o) a.push(k); return
a; }
keys(e1) // ["qwe", "asd"]
keys(e2) // ["zxc", "qwe", "asd"]
It is not part of ecma spec, but "push" is, and "for-in" work well
with objects.
Arrays can be compared (by hand). Thus, exact comparsion is realizable.