Enterprise Integration Zone is brought to you in partnership with:

Software Professional, Open Source Developer & Author. David is a DZone MVB and is not an employee of DZone and has posted 4 posts at DZone. You can read more from them at their website. View Full User Profile

Meet jerg, a JSON Schema to Erlang Records Generator

04.30.2013
| 50159 views |
  • submit to reddit
I'm happy to announce the very first release of my latest Erlang open source project, jerg, a JSON Schema to Erlang Records Generator.

The objective of this project is to be a build tool that parses a rich domain model defined in JSON Schema (as specified in the IETF Internet Draft) in order to generate record definitions that can be used to Erlang applications to both read and write JSON.

I believe that having a formally defined object model for the data that's exchange over web resources is a major plus for APIs. It doesn't necessary imply that consumers have to generate static clients based on such a definition, but as far as the server is concerned, it raises the bar in term of consistency and opens the door for self-generated documentation.

jerg doesn't deal with the actual mapping between JSON and records: there is already a library named json_rec for that. It doesn't also deal with validation as, again, a library named jesse can take care of it.

This first version of jerg generates records with the appropriate type specification to enable type checking with dialyzer. It supports:
  • cross-references for properties and collection items (ie the $ref property),
  • default values,
  • integer enumerations (other types can not be enumerated per limitation of the Erlang type specification).


It also supports a few extensions to JSON schema:
  • extends: to allow a schema to extend another one in order to inherit all the properties of its parent (and any ancestors above it),
  • abstract: to mark schemas that actually do not need to be output as records because they are just used through references and extension,
  • recordName: to customize the name of the record generated from the concerned schema definition.

jerg has a few limitations, like its lack of support for embedded object schemas: pull-requests are more than welcome!

Enough talking: time to get started! Your next stop is jerg's GitHub project. Enjoy!

 

Published at DZone with permission of David Dossot, author and DZone MVB. (source)

(Note: Opinions expressed in this article and its replies are the opinions of their respective authors and not those of DZone, Inc.)