Defining indefinite schema attributes names in JSON schema?

11 views
Skip to first unread message

Steve

unread,
Nov 9, 2009, 5:34:22 PM11/9/09
to JSON Schema
Hi, I've been looking up and down for an answer to this question but
weren't successful -- perhaps I am searching for the wrong words, but
I wasn't able to find anything in the discussion or in the proposal
that addresses this issue.


In either case, consider the following -- I have a JSON file with
headlines for everyday, and it is organized as this:

{
"20091020": [
".........",
".........",
"........."
],
"20091021": [
".........",
"........."
],
...
}

It doesn't have to be dates -- it could be bank accounts that are
"keyed" by the account number. They are done this way so that they can
be looked up quickly without the use of something like JSONPath. The
keys / attribute names are all unique, but they can be in different
combination and it is not practical to define them all as a separate
schema attribute, as there can be hundreds/thousands of these entries.

Is there anyway to put this in JSON schema, or do I have to change the
format to an array w/ a "date" attribute?

Seth Wessitsh

unread,
Nov 9, 2009, 5:49:01 PM11/9/09
to json-...@googlegroups.com
Looks like the schema for your structure should be something like:

{
  type: "object",
  additionalProperties: {
    type: "array",
    items: {type: "string"}
  }
}

The `additionalProperties' restriction takes care of all those properties which aren't explicitly named in the `properties' restriction.  So if no `properties' restriction is present then all properties in the instance are restricted by `additionalProperties`.

Unfortunately, there's no way to define a patten to which all property names must conform.  E.g., you can't say that all property names should have the form of a date or account number.

Seth C. Wessitsh
se...@wessitsh.com

Steve

unread,
Nov 16, 2009, 11:30:44 AM11/16/09
to JSON Schema
Ah thanks for the quick reply!

I don't think I was looking to enforce the property name standard, but
rather a way to not define it in the schema.
I had the impression that you would need to define the property names
for all objects, for example:


{"description":"A person",
"type":"object",
"properties":
{"name": {"type":"string"},
"age" : {"type":"integer",
"maximum":125}}
}


In that example you put in the word "name" and "age" there, where as
in my case I can't really put those in as they could change from file
to file.

Seth Wessitsh

unread,
Nov 16, 2009, 1:43:39 PM11/16/09
to json-...@googlegroups.com
So perhaps there should be another example illustrating the additionalProperties restriction.  I've seen a fair amount of people asking how one is to define the type of an unknown named property.

That was Kris Zyp's example, btw.  He's the creator of the JSON Schema proposal.

Seth C. Wessitsh
se...@wessitsh.com
Reply all
Reply to author
Forward
0 new messages