Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

auto-json-schema

Package Overview
Dependencies
Maintainers
1
Versions
1
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

auto-json-schema

json-schema made easier

  • 1.0.0
  • latest
  • Source
  • npm
  • Socket score

Version published
Maintainers
1
Created
Source

auto-json-schema

json-schema without pain

WhyWhatHowLicense

Why

Because generating json-schema by hand is hard, complex and error prone.

What

The boiler plate stuff are inferred from the values of a model.

var autoS = require('auto-json-schema')
var tedious = {
	type: 'object',
	properties: {'qty': {type: 'number'}, uid:{type: 'string'}},
	$schema: 'http://json-schema.org/schema#'
}
var easy = autoS({
  qty:0,
  uid:''
}) //same result as tedious

The model can contain nested json-schema and additional optional json-schema fragments can be provided to tweek the inferred values.

var autoS = require('auto-json-schema')
var tedious = {
  required: ['uid'],
  type: 'object',
  properties: {
    user: {
      type: 'object',
      properties: {
        age: {
          minimum:18,
          type: 'number'
        },
        uid: {
          pattern: '[a-z]{4}',
          type: 'string'
        }
      }
    }
  },
  $schema: 'http://json-schema.org/schema#'
}
var easier = autoS({
  user: {
    age: autoS(0, { minimum:18 }),
    uid: autoS('', { pattern:'[a-z]{4}' })
  }
}, {
  required: ['uid']
}) //same result as tedious

How

  • autoSchema(model, schemaFragment, schemaFragment, ...)
  • model: any valid json structure. The value can be sub-schema. Examples:
    • 3: a standalone primitive
    • {value: 3, password: anotherSchemaObject}: a mix of values, tructures and schema
  • schemaFragment: any valid parts of the json-schema standard. Last entries take precedence.
    • {type: 'integer'}: to overide the inferred type

License

Released under the MIT License

Keywords

FAQs

Package last updated on 17 Oct 2016

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc