The JSON Schema Generator creates a JSON Schema from a JSON Document
The JSON Schema Generator tool uses a Wizard to create a compliant JSON Schema by inferring its structure from a sample JSON document. Configuration options control the rules used when inferring the schemas structure.
The pipeline for rapid JOSN Schema creation is as follows:
Why use a JSON Schema?
- Provides a formal, unambiguous description, essential for distribution to 3rd parties
- Validation of JSON documents.
- JSON development tools use them to provide intellisense and autocomplete
- Reduces the amount of validation code needed in client applications
- Basis for generating a data layer for your application (JSON Data Binding)
- Forms the basis of formal documentation for your data model
Inferring a JSON Schema
You can infer a JSON Schema from a JSON file open in the Liquid Studio editor, or using the quick start wizard on the start screen.
The Generation Options configure how the wizard should interpret the properties, values and arrays in the source data. When the JSON to JSON Schema converter processes the source data, there will often be more than one potential interpretation. Depending on the amount of source data, it may not be clear whether there is a minimum or maximum number of times an item must appear in an array, or whether a particular property is required or optional. Similarly, the source data may not provide sufficient information to infer value data types. To address this options are provided to allow control the conversion, they also control whether the resulting schema is open or closed.
Example - Inferring a JSON Schema from a JSON Sample Document
We will use the following sample JSON document to demonstrate the effect of the Generation Options:
{ "Book": [ { "Title": "The Graveyard Book", "Price": 4.99, "ISBN": "978-0747596837", "Genre": "Horror", "Author": [ { "FirstName": "Neil", "Surname": "Gaiman" } ] }, { "Title": "XML Schemas", "Price": 21.99, "ISBN": "0-596-00252-1", "Genre": "Reference", "Author": [ { "FirstName": "Eric", "Surname": "van der Vlist" } ] } ] }
The following JSON Schema is inferred from the sample JSON data above.
{ "$schema": "http://json-schema.org/draft-04/schema#", "type": "object", "properties": { "Book": { "type": "array", "items": { "type": "object", "properties": { "Title": { "type": "string" }, "Price": { "type": "number" }, "ISBN": { "type": "string" }, "Genre": { "type": "string" }, "Author": { "type": "array", "items": { "type": "object", "properties": { "FirstName": { "type": "string" }, "Surname": { "type": "string" } }, "additionalProperties": false, "required": [ "FirstName", "Surname" ] }, "additionalItems": false } }, "additionalProperties": false, "required": [ "Title", "Price", "ISBN", "Genre", "Author" ] }, "additionalItems": false } }, "additionalProperties": false, "required": [ "Book" ] }
Once you have your JSON Schema the way you want it, you can test it out by using it to validate some JSON data you plan on using with your project. With the JSON file open, add the JSON Schema to the document by selecting "Attach Schema" from the toolbar or Tools menu and browsing to a JSON Schema file you inferred. Once the JSON Schema has been cited within the document, clicking the Validate button or choosing it from the Tools menu will check the XML against the generated JSON Schema.
Once you have a JSON Schema added to a JSON document, you will see Schema-aware intellisense as you edit the data in the source view, prompting you with elements and attributes appropriate to the structures defined within the Schema, relative to your position in the data.