How to define external enum values

992 views
Skip to first unread message

stephenbeattie

unread,
Sep 15, 2009, 6:56:13 PM9/15/09
to JSON Schema
Hello all,

I'm excited by the potential of JSON Schema but I can't see how I can
define (or reference) an external list of options for an enum property
type.

For example, if I have a schema that I want to generate a form for,
how might I go about adding an enum property (which I'll show as a
dropdown menu) with an array of choices that are defined as
{ "value":"blah blah", "label":"woof woof" } objects externally to the
schema itself ?

"colour": {
"type": "string",
"title": "Favourite Colour",
"description": "Your favourite colour",
"enum": "$json:http://www.mysite.com/colours.json"
}

The snippet above shows what I'd like to do for the "enum" options -
point at a JSON file containing the array of options. This is
currently my wishful thinking but is there anything in the spec that
allows this functionality ?

thanks

Stephen

Seth Wessitsh

unread,
Sep 15, 2009, 7:00:53 PM9/15/09
to json-...@googlegroups.com
enum is used only to list all allowable values for an instance not to actually
create labels.  You can use options for that purpose.

To reference your options set you could then do

"colour": {

   {"$ref": "http://www.mysite.com/colours.json"}

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

Seth Wessitsh

unread,
Sep 15, 2009, 7:03:32 PM9/15/09
to json-...@googlegroups.com
Sorry 'bout that, sent too early.

The example should be
"colour": {
       "type": "string",
       "title": "Favourite Colour",
       "description": "Your favourite colour",
       "enum": {"$ref": "http://www.mysite.com/colours.json"}
}

assuming http://www.mysite.com/colours.json contains :

options: [ {"value":"blah blah", "label":"woof woof"} ]

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

Seth Wessitsh

unread,
Sep 15, 2009, 7:04:55 PM9/15/09
to json-...@googlegroups.com
Ok, again sorry. My brain doesn't seem to be working right now

The example should -really- be
"colour": {
       "type": "string",
       "title": "Favourite Colour",
       "description": "Your favourite colour",
       "options": {"$ref": "http://www.mysite.com/colours.json"}
}

assuming http://www.mysite.com/colours.json contains :

[ {"value":"blah blah", "label":"woof woof"} ]

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


Stephen Beattie

unread,
Sep 15, 2009, 7:24:25 PM9/15/09
to json-...@googlegroups.com
Seth, that's great!  I'll give this a go.

many thanks

Stephen


2009/9/16 Seth Wessitsh <se...@wessitsh.com>
Reply all
Reply to author
Forward
0 new messages