Monday, April 20th, 2009

How JSON Schema is turning out for the Chrome extension APIs

Category: Chrome, JSON

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:


  1. chromium.tabs.createTab = function(tab, callback) {
  2.   validate(arguments, arguments.callee.params);
  3.   sendRequest(CreateTab, tab, callback);
  4. };
  6. chromium.tabs.createTab.params = [
  7.   {
  8.     type: "object",
  9.     properties: {
  10.       windowId: chromium.types.optPInt,
  11.       url: chromium.types.optStr,
  12.       selected: chromium.types.optBool
  13.     },
  14.     additionalProperties: false
  15.   },
  16.   chromium.types.optFun
  17. ];

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.

Posted by Dion Almaer at 5:19 am

3.8 rating from 14 votes


Comments feed TrackBack URI

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.

Comment by kriszyp — April 20, 2009

The code example has been cut short…

Comment by icoloma — April 20, 2009

Nah, my fault. It’s fine.

My Firefox is going maracas these days…

Comment by icoloma — April 20, 2009

What three letter acronym is what we use to style web pages?

Comment by sora — December 9, 2010

Leave a comment

You must be logged in to post a comment.