Socket
Socket
Sign inDemoInstall

json-schema-compare

Package Overview
Dependencies
1
Maintainers
1
Versions
3
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    json-schema-compare

Compare json schemas smarter.


Version published
Weekly downloads
651K
decreased by-14.55%
Maintainers
1
Install size
1.37 MB
Created
Weekly downloads
 

Readme

Source

json-schema-compare Build Status Coverage Status

Compare json schemas correctly

npm install json-schema-compare --save
var compare = require('json-schema-compare')

var isEqual = compare({
  title: 'title 1',
  type: ['object'],
  uniqueItems: false,
  dependencies: {
    name: ['age', 'lastName']
  },
  required: ['name', 'age', 'name']
}, {
  title: 'title 2',
  type: 'object',
  required: ['age', 'name'],
  dependencies: {
    name: ['lastName', 'age']
  },
  properties: {
    name: {
      minLength: 0
    }
  }
}, {
  ignore: ['title']
})

console.log(isEqual) // => true

Compare json schemas correctly.

  • Ignores sort for arrays where sort does not matter, like required, enum, type, anyOf, oneOf, anyOf, dependencies (if array)
  • Compares correctly type when array or string
  • Ignores duplicate values before comparing
  • For schemas and sub schemas undefined, true and {} are equal
  • For minLength, minItems and minProperties undefined and 0 are equal
  • For uniqueItems, undefined and false are equal

Options

ignore array - default: []

Ignores certain keywords, useful to exclude meta keywords like title, description etc or custom keywords. If all you want to know if they are the same in terms of validation keywords.

Contributing

Create tests for new functionality and follow the eslint rules.

License

MIT © Martin Hansen

Keywords

FAQs

Last updated on 22 Oct 2017

Did you know?

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

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc