Sign Up for Free

RunKit +

Try any Node.js package right in your browser

This is a playground to test code. It runs a full Node.js environment and already has all of npm’s 400,000 packages pre-installed, including json-api-schema with all npm packages installed. Try it out:

var jsonApiSchema = require("json-api-schema")

This service is provided by RunKit and is not affiliated with npm, Inc or the package authors.

json-api-schema v0.0.7

JSON Api Schema is a JSON dialect that can describe any Web Based API that uses JSON to exchange data.

JSON Api Schema

A Json based Web API Description Language and Object Model

JSON Api Schema is a JSON dialect ( just a json file ) that can describe any Web Based API that uses JSON to exchange data.

A JSON Api Schema can be used to share an unabiguous object model between servers and clients along with validation logic, classes and so on.

In other words JSON Api Schema is a set of two related specification:

  • JSON Api Schema-DL: A JSON API Description Language
  • JSON Api Schema-OM: A related API Object Model (similar of what DOM is to HTML)

Design goals

Be generic enough to describe complex systems

JSON Api Schema is designed to express a generic API minimizing constraints on implementations. JSON Api Schema Description Language can support applicaition specific behaviours through extensions. JSON Api Schema is designed to be able to express a super-set of RESTful APIs and JSON APIs, as a mean to communicate interactions and data structures exposed by an API. Application specific stuffs are expressed through protocol options.

Be available in multiple languages

JSON Api Schema Object Model adopt conventions that make it easy to be implemented in most languages. For example we use getters and setters over properties and accessors, iterators instead of closures, ecc...

Be suitable to readapt existing data models

Being easy to implement in both clients and servers JSON Api Schema is perfect to renew an old data source.

Be a real-world solution

To be different from other well known solution it primarly targets modern web development (A Javascript friendly solution, easy to map validation errors to form fields, support for websockets, EventSources ecc..., and more over not be a two billion SLOC framework).

Allow to share validation logic between servers and clients

JSON Api Schema heavily relies on JSON Schema to export validation logic to clients.

Be suitable to build RMI on top of it

Implementing Types JSON Api Schema makes it easy (but not forces) to hide network requests behind OOP objects and classes.

Be documentable

JSON Api Schema support documentation attributes everywhere. A traversable model make it easy to generate a beautiful readable documentation.

A typical use case

An application consists of a data api, a website and a mobile app:

  • They are 3 separate systems that may be written in different languages.
  • They shares the same domain model.

Data Api exports its interface through JSON Api Schema. Website and Mobile App consumes that through dynamically or statically generated stubs, or either by directly calling actions via ajax requests.


Api Model (For Both DL and OM):


The entry point of the model. An Api is a set of interactions, types and resources. An api exposes also protocol specific global informations to configure interactions.

#### Resource

A Resource is a type that has interactions. A Resource can have nested resources. Nested resources are somewhat logically bound to their container, eg. by ID or by URI.


A JSON Schema instance. Anything that can be validated should have or be a schema.

#### Type

Just a named Schema.


An interaction is a communication available with the api. It can represent both a client-initiated communication or a server initiated communication. Protocol based informations about an interaction are stored in a protocols map.


An action is a client initiated interaction. It has two validatable sub-entities along with protocol specification: params and returns


An event is a server initiated interaction. It has a validatable sub-entity along with protocol specification: params.


RunKit is a free, in-browser JavaScript dev environment for prototyping Node.js code, with every npm package installed. Sign up to share your code.
Sign Up for Free