Name: jsonschemer
Owner: Vivocha
Description: Automatically guesstimate a JSON Schema from the contents of a MongoDB collection
Created: 2016-05-03 10:14:09.0
Updated: 2016-05-05 09:25:53.0
Pushed: 2016-05-05 10:27:33.0
Homepage: null
Size: 6
Language: JavaScript
GitHub Committers
User | Most Recent Commit | # Commits |
---|
Other Committers
User | Most Recent Commit | # Commits |
---|
Automatically guesstimate a JSON Schema from the contents of a MongoDB collection
install jsonschemer
schemer [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.schemer -q '{ "surname":"Smith" }' mongodb://10.0.0.1:27017/my_db users
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.schemer = require('jsonschemer');
mer({
: 'mongodb://10.0.0.1:27017/my_db'
llection: 'users',
xEnum: 20,
{ surname: 'Smith' }
hen(function(schema) {
nsole.log(JSON.stringify(schema, null, 2));