NPM Version License Code Coverage JavaScript Style Guide

A JavaScript Model class designed to serialize and transfer structured data within the services/apps you build or across networks. It is paired with Schema(JSON)js to provide structure and validation capabilities to your data model.

Motivations behind the project:

  • implement a data serialization solution for structured JSON data
  • backed with JSON Schema definition/validation
  • leverage modern JS features
  • small and lightweight with only one dependency
  • universal support for the latest browsers and Node.js
  • no code generation



Install using npm:

npm install --save model-json-js


Below are a few examples on how to use the Model and Schema classes. For the sake of the following examples, here is a sample Schema we'll reference with all the examples.

// JSON Schema
const TestSchema = {
  title: 'Test',
  $id: '',
  type: 'object',
  properties: {
    test: {
      type: 'string'
    another: {
      type: 'string'
  required: ['test']
// model FSA
const testData = {
  type: 'Test',
  payload: { test: 'object' }


  • An example Model initialized with raw data and schema.

    const model = await new Model(testData, TestSchema)
  • An example Model initialized with a cached JSON Schema references defined.

    const testSchema = await new Schema(TestSchema)
    // ...
    const model = await new Model(testData, testSchema)
  • An example immutable Model initialized with raw data and schema.

    const model = await new Model(testData, TestSchema, { immutable: true })


  • Validate the entire Model.

    const isValid = Model.validate(model)
  • Validate a single property of the model

    const isValid = Model.validate(model.test, Model.schema(model).test)


  • Serialize the Model with JSON stringify.

    const json = JSON.stringify(model)



  • All modern browsers and Node 10+ without polyfills.


  • create contributing guide
  • feature requests via issues


We are currently drafting our contributing guide in the new monorepo!