Received: by 10.66.81.98 with SMTP id z2mr5129908pax.19.1349870408820; Wed, 10 Oct 2012 05:00:08 -0700 (PDT) X-BeenThere: mongodb-user@googlegroups.com Received: by 10.68.197.72 with SMTP id is8ls1712272pbc.5.gmail; Wed, 10 Oct 2012 04:59:58 -0700 (PDT) Received: by 10.68.212.99 with SMTP id nj3mr5929979pbc.20.1349870398521; Wed, 10 Oct 2012 04:59:58 -0700 (PDT) Date: Wed, 10 Oct 2012 04:59:58 -0700 (PDT) From: Stephen Steneker To: mongodb-user@googlegroups.com Message-Id: In-Reply-To: References: Subject: Re: Any way to generate a JSON-Schema from a Collection? MIME-Version: 1.0 Content-Type: multipart/mixed; boundary="----=_Part_2035_1009432.1349870398057" ------=_Part_2035_1009432.1349870398057 Content-Type: multipart/alternative; boundary="----=_Part_2036_20535471.1349870398057" ------=_Part_2036_20535471.1349870398057 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit > > > 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/) * JSON-Schema-Generator (https://github.com/jsonschema/JSON-Schema-Generator) * 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 ------=_Part_2036_20535471.1349870398057 Content-Type: text/html; charset=utf-8 Content-Transfer-Encoding: quoted-printable

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

H= i Julien,

A few folks have mentioned interest in using JSON S= chema 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-sche= ma/)
 * JSON-Schema-Generator (https://github.com/jsonschema= /JSON-Schema-Generator) 
 * JSV: JSON Schema Validator = (https://github.com/garycourt/JSV)

Schema.js uses MapReduce t= o work out the coverage and types of fields in a collection, so you could m= assage the results from that to generate your JSON Schema.  For exampl= e, you could infer based on the 'coverage %' whether a field should be opti= onal or required.  You could use JSV to validate documents against the= expected schema.

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

Cheers,
Stephen

------=_Part_2036_20535471.1349870398057-- ------=_Part_2035_1009432.1349870398057--