3 ms·
I took a KI(RF)SS stab at a JSON schema description language, attempting to avoid the insanity of the XML world but still provide a bit of structure for JSON, a
by carsongross 12y ago
I took a KI(RF)SS stab at a JSON schema description language, attempting to avoid the insanity of the XML world but still provide a bit of structure for JSON, a while back:
http://jschema.org/ http://jschema.org/
Haven't touched it in a few years, but I think the core idea is sound: as much schema as can be packed into 15 additional productions beyond the original 15 in the JSON spec.
I wrote a typeloader for Gosu based on it:
http://vimeo.com/29348322 http://vimeo.com/29348322
- skrebbel 12y agoI once braindumped a similar idea on https://github.com/eteeselink/relax-json https://github.com/eteeselink/relax-json (inspired by RELAX NG, one of the few great things to come out of the XML world). A core difference between it and your JSchema is that it, itself, is not JSON - just like XML, I don't think JSON makes for a good format to write down schema definitions. In fact, I don't think JSON is very human friendly at all[0], which is OK for a data interchange format, occasionally read by humans but hardly ever written by hand. I did not further develop RELAX JSON, however, when I realized that TypeScript interface definitions[1] are a great JSON schema language: enum Color { Yellow, Brown }; interface Banana { color: Color; length: number; } interface FruitBasket { bananas: Array<Banana>; apples: Array<{color: Color; radius: number}>?; } It's best to use interfaces and not classes, because interfaces allow for optional fields (with the `?` suffix), which is pretty common in APIs and wherever JSON is used. I will write a validate-JSON-with-TypeScript-type-definitions checker as soon as I find a need for it. Open to ideas here, guys! (or alternatives) [0] Compare gruntfiles to webpack configs (tl;dr: they're JSON and JS-that-returns-an-object, respectively. the latter allows code, comments, unquoted keys, etc etc). [1] http://www.typescriptlang.org/Handbook#interfaces http://www.typescriptlang.org/Handbook#interfaces