Socket
Book a DemoInstallSign in
Socket

jsonschemer

Package Overview
Dependencies
Maintainers
1
Versions
3
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

jsonschemer

Automatically guesstimate a JSON Schema from the contents of a MongoDB collection

latest
Source
npmnpm
Version
1.1.0
Version published
Weekly downloads
2
100%
Maintainers
1
Weekly downloads
 
Created
Source

jsonschemer

Automatically guesstimate a JSON Schema from the contents of a MongoDB collection

Installation

npm install jsonschemer

Usage

jsonschemer [options] <db connection string> <collection>

Valid options are:

  • -q, --query, filter the documents to analyze using the specified JSON query.
  • -l, --limit, limit the number of documents to analyze.
  • -m, --maxEnum, limit the number of possible enum values. When encountering a string type, the tool assume its possible values are fixed and starts adding each encountered value to an enum clause in the schema. If more than maxEnum different values are found, the enum is dropped from the schema.

Example

jsonschemer -q '{ "surname":"Smith" }' mongodb://10.0.0.1:27017/my_db users

Usage with Node.js

The exports of the library are a single function, accepting an options object and returning a promise resolved to the resulting JSON Schema.

Options can have the following properties:

  • db, required, a MongoDB database object (as returned by MongoClient.connect) or a connection URI string.
  • collection, require, the MongoDB collection to query.
  • q, optional, a query to filter the documents in the collection.
  • limit, optional, maximum number of documents to analyze.
  • maxEnum, optional, default 20, maximum number of items in a schema enum.

Example

var schemer = require('jsonschemer');

schemer({
  db: 'mongodb://10.0.0.1:27017/my_db'
  collection: 'users',
  maxEnum: 20,
  q: { surname: 'Smith' }
}).then(function(schema) {
  console.log(JSON.stringify(schema, null, 2));
});

Keywords

json

FAQs

Package last updated on 05 May 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