Monday, April 20th, 2009
How JSON Schema is turning out for the Chrome extension APIs
When Aaron talked about the Chrome extension API he mentioned how he would see if JSON Schema could help them have a JSON heavy API and allow them to easily validate.
He has quickly reported back and is happy with the results.
Something like this:
- chromium.tabs.createTab = function(tab, callback) {
- validate(arguments, arguments.callee.params);
- sendRequest(CreateTab, tab, callback);
- };
- chromium.tabs.createTab.params = [
- {
- type: "object",
- properties: {
- windowId: chromium.types.optPInt,
- url: chromium.types.optStr,
- selected: chromium.types.optBool
- },
- additionalProperties: false
- },
- chromium.types.optFun
- ];
will give you errors such as:
Invalid value for parameter 0. Property windowId: expected integer, got string.
It will be interesting to see how the APIs look when you go for this style throughout. Looking forward to see more.





Aliasing common types with JS variables like Aaron has done is excellent way of making more succinct, readable schemas by utilizing the local language features.
The code example has been cut short…
Nah, my fault. It’s fine.
My Firefox is going maracas these days…
What three letter acronym is what we use to style web pages?