Any way to generate a JSON-Schema from a Collection?

2,817 views
Skip to first unread message

Julien Chaumond

unread,
Oct 10, 2012, 3:48:08 AM10/10/12
to mongodb-user
Hi,

Has anyone worked on a way to generate a (tentative) JSON-Schema
(http://json-schema.org/) from an existing Collection?

Thanks,

Julien

Reno Reckling

unread,
Oct 10, 2012, 5:21:18 AM10/10/12
to mongod...@googlegroups.com
Hi

> Has anyone worked on a way to generate a (tentative) JSON-Schema
> (http://json-schema.org/) from an existing Collection?

Wouldn't that imply that a collection even has a specific schema?
In mongodb every document within a collection can have a different structure so generating a schema
for a collection seems a little bit pointless.
Or am I missing something?

Regards,
Reno

Julien Chaumond

unread,
Oct 10, 2012, 7:03:08 AM10/10/12
to mongodb-user
Hi Reno,

Well, the fact that a Collection doesn't need to have a schema doesn't
mean it can't have a schema, right?

Julien

Sam Millman

unread,
Oct 10, 2012, 7:53:57 AM10/10/12
to mongod...@googlegroups.com
I do not believe anyone has.

I have to be honest, this is the first time I have seen this and since it is only a draft and not a recognised schema/standard I doubt there has been much work with MongoDB in relation to this schema type.



--
You received this message because you are subscribed to the Google
Groups "mongodb-user" group.
To post to this group, send email to mongod...@googlegroups.com
To unsubscribe from this group, send email to
mongodb-user...@googlegroups.com
See also the IRC channel -- freenode.net#mongodb

Stephen Steneker

unread,
Oct 10, 2012, 7:59:58 AM10/10/12
to mongod...@googlegroups.com

Has anyone worked on a way to generate a (tentative) JSON-Schema 
(http://json-schema.org/) from an existing Collection? 

Hi Julien,

A few folks have mentioned interest in using JSON Schema Validation but I haven't come across any generic implementations for generating or validating JSON-Schema from MongoDB yet.

Some ingredients that may help you get started:
 * Schema.js: a MongoDB schema analysis tool (http://skratchdot.com/projects/mongodb-schema/)
 * JSV: JSON Schema Validator (https://github.com/garycourt/JSV)

Schema.js uses MapReduce to work out the coverage and types of fields in a collection, so you could massage the results from that to generate your JSON Schema.  For example, you could infer based on the 'coverage %' whether a field should be optional or required.  You could use JSV to validate documents against the expected schema.

I'd be interested to see if anyone does have solutions.  The JSON-Schema spec is still an evolving draft so you would definitely be an early adopter ;-).

Cheers,
Stephen

Travis Laborde

unread,
Oct 10, 2012, 9:28:49 AM10/10/12
to mongod...@googlegroups.com
there is a nice script available here that might help you: https://github.com/variety/variety


Travis
Reply all
Reply to author
Forward
0 new messages