John Calcote wrote:
> Hi - It's not clear to me from this specification how one would go
> about describing internal references. For the schema that I'm
> currently working on, I'm simply using the external reference format
> described in the proposal, but it's not really clear that this is the
> appropriate thing to do. For a concept as important as sub-schema
> referencing, I should think that the specific syntax would be
> explained in greater detail. Sub-schema referencing is critical to
> reduce redundancy in larger more complex schemas, wouldn't you agree?
>
>
I agree, you are correct. More examples/explanation should be included.
> Example (admittedly contrived):
> [
> { "id":"book",
> "type":"object",
> "properties":{"title":"string", "author":"string",
> "isbn":"string"}
> },
> { "description":"library",
> "type":"object",
> "properties":{"Books":{type":"book"}
> }
> ]
>
You have the right idea, I think your second schema would look like:
{ "description":"library",
"type":"object",
"properties":{
"Books":{
"items":{"$ref":"book"}
}
}
}
And I assuming here that you actually want the Books property in the
library objects to be an array, where each item in the array is a book
(hence the reference to the book schema). Anyway, I will try to get at
least another example on the specification page.
Thanks,
Kris
> --john
> >
>
Fred wrote:
> Hi Guys,
>
> I'm interested in using JSON to define some data structures that I
> will be passing over a serial connection. The definitions will be hand
> written and static with respect to the release version of the project.
> Because they are hand written I'd like to provide schemas and use them
> myself to check my work before releasing.
>
> I have a couple of questions.
>
> 1) There seem to be other json schemas, how can I be certain that this
> one is the one that will be standardised?
>
I was not aware of any competitors (nor is my google search results for
"JSON Schema"). There are a few other schema languages that can be used
to validate JSON (like Cerny and Kwalify, which is cited in the spec),
but that aren't JSON-based, they written in other languages. I did a the
search for a JSON schema and basically all the top results (except for
the non-JSON based exceptions) seem to point back to this proposal. Do
you have any particular alternative in mind?
> 2) The specification is (to me) unclear with respect array
> definitions. I'd love to see some different examples of array schema
> definitions in the guide/spec.
>
Good suggestion, I added another short example in the working draft page
(search for hobbies).
> 3) At a quick glance I couldn't see a way of describing repeating
> elements, is this possible or even desirable to do? Or should I just
> use arrays as I have currently drafted?
>
Repeating elements are described with arrays in JSON, and JSON Schema
doesn't attempt to contradict that.
Thanks,
Kris
Fred wrote:
> Hi, thanks for the response :-)
>
>
>>> 1) There seem to be other json schemas, how can I be certain that this
>>> one is the one that will be standardised?
>>>
>> I was not aware of any competitors (nor is my google search results for
>>
> <snip>
>
>> you have any particular alternative in mind?
>>
>
> This was what prompted me to ask :
>
> http://www.kruse-net.dk/json-schema/
>
Jakob actually discussed this on this discussion group and I believe we
incorporated some of his suggestions in this proposal, if i recall. It
appears that his comments are on an older version of JSON schema and
were fixed, thus it actually became part of the evolution of the current
proposal.
Kris
I think the idea of having a specific order is not just specific to form
generation. Yes, this is a usecase, but i think having an specific order
has more benifits. One of the main things that attract me to JSON is the
compact readable syntax, being able to print out a JSON document and
know exactly where to find things is a nice feature. However, this is
lost if the order is not gauranteed.
I disagree that the order should not be preserved by default. It feels
that the reason for this is that many languages implement an object as
an unordered hash map. I do not think JSON nor JSON Schema should be
concerned with how the object is implemented internally, but should be
more concerned on the usage of both documents (Schema and Conforming
Document).
IMHO, i think the order should be preserved by default and having an
option to say order is not important. It could also be the other way
around, but for the reason mentioned above I think order is something
important.
--
Hatem Nassrat
PS. I posted an EBNF like schema that I have used to document a set of
JSON documents. As a specification in that schema was that order must be
preserved. Moreover, the simplest validating parser of that schema would
require things to appear in the right order (this is just a bonus, again
as I mentioned, this shouldn't be the reason to do things one way or the
other).
I think you have missed what I was trying to say. JSON is a data
representation, making the JSON object be specified as an unordered set
of key value pairs makes it resemble the data structure which implements
it. IMHO data representation should not be coupled to the way the data
would be implicitly stored (when it is no longer in a JSON document).
To reiterate, the JSON document itself is an ASCII (or some encoding)
file, the charachters in the file will not jumble themselves. However,
the specification means that programs may put key value pairs of a JSON
object into a JSON document with arbitrary order, although this gives
the system the flexibility to use an unordered hash map to represent a
JSON object it doesn't make much sense to impose such a data structure
on all JSON users (whether human or software).
For the purpose of human readability my argument is the order makes it
easy to locate the data being represented by the JSON data
representation.
--
Hatem Nassrat
PS. JSON should not be 1-1 mapped to JavaScript even if it has it in the
name. Moreover, JSON objects are not 1-1 mapped to JavaScript Objects
(e.g. you do not need to quote (even double quote) your keys with
JavaScript).
Schemas generally define logical content and data model, but less
often "cosmetic" aspects, such as optimal configuration for display on
GUIs (or details of serialization process). And given that JSON data
model itself explicitly states that there is no implied logical
ordering for object fields (just physical one, which is arbitrary,
conceptually), it really does not seem like this would be an ideal
thing to include.
But perhaps there could be section(s) of additional optional related
data, within schema specification.
-+ Tatu +-
In the schema for the "more sophisticated" example, above, there is a
missing quotation mark:
{"value:"male","label":"Guy"},
should be:
Click on http://groups.google.com/group/json-schema/web/json-schema-proposal-working-draft?hl=en_US
- or copy & paste it into your browser's address bar if that doesn't
work.
Petri
Kris
--
Thanks,
Kris
I don't see any other properties than "optional" in the core schema
definition that are boolean. It is false by default, which is
intuitive, but I don't think that one property is enough to set a
standard that the "minimumCanEqual" and "maximumCanEqual" need to be
consistent with.
Petri
In XML, you typically specify the order in the XSD using Sequence tag. It's actually convenient if you expect certain application down the line to actually read traverse the data blindly. There are many XSDs that I have encountered that have (and don't have) specified sequence and with a good validator, there isn't really an issue. If you XSD generator in the other hand create XSD with different order and slap a Sequence tag on top like some IBM tools do, that's a different story.
I don't see how the validator (or any application) actually care unless it's very rigid and can only read the data and schema from top to bottom only.
Adding order adds a lot of complexity without solving much of anything in this case in my opinion. Am I misunderstanding something?
Thanks,
Jack
On Jun 27, 2011, at 4:14 AM, James Godfrey <jgodf...@gmail.com> wrote:
> This design is seriously flawed in the same way that XML Schemas are
> flawed - they don't explicitly address the order of elements. In JSON,
> as with XML, the order of elements are completely irrelevant e.g.
>
> { "name" : "John Doe",
> "age" : 30 }
>
> { "age" : 30,
> "name" : "John Doe"}
>
> Should both be able to be validated using the same schema since they
> produce the same output. But given the complete lack of reference to
> element order in the draft each validator implementation might produce
> a different output.
>
> The draft needs to address the order of elements within JSON, and to
> make it actually useful it needs to "ignore" or normalise the data so
> elements on the same level of the hierarchy. I'd like to see explicit
> ordering of elements be an optional feature, but one which should be
> off by default since within the JSON language explicit ordering is
> unused by default.
>
> XML Schemas are very often not used simply because you have to keep
> XML elements in a specific order even though that was never a
> requirement in the XML markup its self.
>
> --
> 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.
>
This design is seriously flawed in the same way that XML Schemas are
flawed - they don't explicitly address the order of elements. In JSON,
as with XML, the order of elements are completely irrelevant e.g.
{ "name" : "John Doe",
"age" : 30 }
{ "age" : 30,
"name" : "John Doe"}
Should both be able to be validated using the same schema since they
produce the same output. But given the complete lack of reference to
element order in the draft each validator implementation might produce
a different output.
The draft needs to address the order of elements within JSON
, and to
make it actually useful it needs to "ignore" or normalise the data so
elements on the same level of the hierarchy.
I'd like to see explicit
ordering of elements be an optional feature, but one which should be
off by default since within the JSON language explicit ordering is
unused by default.
XML Schemas are very often not used simply because you have to keep
XML elements in a specific order even though that was never a
requirement in the XML markup its self.
“An object is an unordered collection of zero or more name/value pairs…”
This design is seriously flawed in the same way that XML Schemas are
flawed - they don't explicitly address the order of elements. In JSON,
as with XML, the order of elements are completely irrelevant e.g.
{ "name" : "John Doe",
"age" : 30 }
{ "age" : 30,
"name" : "John Doe"}
Should both be able to be validated using the same schema since they
produce the same output. But given the complete lack of reference to
element order in the draft each validator implementation might produce
a different output.
The draft needs to address the order of elements within JSON, and to
make it actually useful it needs to "ignore" or normalise the data so
elements on the same level of the hierarchy. I'd like to see explicit
ordering of elements be an optional feature, but one which should be
off by default since within the JSON language explicit ordering is
unused by default.
XML Schemas are very often not used simply because you have to keep
XML elements in a specific order even though that was never a
requirement in the XML markup its self.