Skip to content

[WIP] Parser to convert condensed JSON schemas to standard ones.

License

Notifications You must be signed in to change notification settings

frctl/json-schema

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

29 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

JSON Schema

Parser to convert condensed JSON schemas to standard ones.

Build Status NPM Version

Overview

This is a parser that generates a fully qualified JSON Schema based on 'condensed' JSON schema input. From Understanding JSON Schema:

JSON Schema is a powerful tool for validating the structure of JSON data.

Rationale

JSON Schema is extremely useful for validation purposes; however, in some use cases it may also be more verbose than necessary. This tool was created to allow users of Fractal to add specifications to their components, whilst hiding some of the complexity of the full specification.

const schemaExpander = require('@frctl/json-schema');

const schema = schemaExpander.expand({ title: 'string', modifier: 'string' });

console.log(schema);

/*
Outputs:

{
  "$schema": "http://json-schema.org/schema#",
  "type": "object",
  "properties": {
    "title": {
      "type": "string"
    },
    "modifier": {
      "type": "string"
    }
  }
}

*/

Installation

npm i @frctl/json-schema --save

API

.expand(schema)

Returns a fully qualified JSON schema.

const schema = jsonSchema.parse({ title: 'string', modifier: 'string' });
  • If a valid condensed schema is provided, a converted, fully qualified schema will be returned.
  • If an already fully qualified schema is provided, it will return that.
  • If an invalid schema is provided, it will return an empty schema (i.e. all data will validate).

Resources

Requirements

Node >= v6.0 is required.

About

[WIP] Parser to convert condensed JSON schemas to standard ones.

Resources

License

Stars

Watchers

Forks

Packages

No packages published