JSON2Schema is a small WebApp with a node JS library running totally in your browser, that supports developers in creating a JSON Schema for the JSON Editor by Jeremy Dorn. The corresponding NPM module json2schema is library that converts a JSON into a JS
json-editor package in https://www.github.com/json-editor/json-editorThe corresponding NPM module json2schema4editor (JSON to(2) Schema for(4) Editor means that the JSON schema is created for the JSON editor json-editor](https://www.github.com/json-editor/json-editor).
https://niehausbert.gitlab.io/JSON2Schema
Copy a JSON of your choice into the JSON2Schema tool and create a raw JSON schema, that works in the JSON editor
Table of Contents generated with DocToc
- Quickstart
- What is a JSON Schema?
- How Create a JSON Schema
- ZIP File jsoneditor_app.zip
- Application of jsoneditor_app.zip in JSON2Schema
- Exchange jsoneditor_app.zip for JSON Editor Generation
- (1) Modify the Editor jsoneditor\_app.zip
- (2) Modify the JSON2Schema Tool in JSON2Schema-master.zip
- Why is the base64 encoded used for JSON2Schema?
- Acknowledgement
Export JSON Editor as ZIP button creates a ZIP file and will be saved in your download folder. If you try to start the index.html directly from the compressed ZIP file, the JSON editor will not work. Unzip/uncompress all files first and load the index.html from the extracted folder.oneOf element in the JSON schema.jsoneditor_app.zip by pressing the Export JSON Editor button.
npm install json2schema4editor --save
`
Then you can require the module json2schema4editor in your script:`javascript
const j2s = require('json2schema4editor');
let schema_title = "My Title for the Schema";
let my_json = {
"firstname": "Bert",
"lastname": "Bond",
"gender": "___SELECT___male|female|other",
"email": "noname@example.com"
};
let my_schema = j2s.getSchema4JSON(my_json,schema_title);
`
The module contains also a generator for a draft template for Handlebars resp. Handelbars4Code.What is a JSON Schema?
A JSON Schema is a basically a file, that defines the type and the layout of the input in the JSON editor. The input elements are defined for each key-value pair (e.g. firstname="Bert" in a given JSON. In this case we use the JSON Editor by Jeremy Dorn. I.e. the JSON Schema tells the editor that the user of the JSON editor:
* Edit a string value with a select box (e.g. for male/female/other),
* Edit a string with a free text input as a single line.
* Edit a string with a free text input with multiple lines (e.g. with syntax highlighting for a specific programming language).
* uses a select box for different options in the graphical user interface GUI,
* select a color,
* select a data,
* increase or decrease an integer value, with a specific range and check validity with regular expressions for the input element,
* ...What is a Handlebars4Code Template?
Javascript template engines take a JSON as input and fill a template with the content of the JSON. The template contains markers like {{firstname}} and the JSON contains the data for replacement of the marker with the specific content from the JSON (e.g. Paul or Anna). With a Javascript template engines like
* Mustache,
* Handelbars,
* ...
you define the structure and syntax of the output.
Handlebars4Code extends Handlebars Template Engine with additional HandlebarsJS helpers for code generation. Handlebars4Code is integrated in JSON2Schema to add a raw template for output by generated AppLSAC, which runs offline in your browser as runtime environment for Javascript code without the need perform a generation of code on the server side.Submit JSON to a Restful API
The generated ZIP contains a WebApp (AppLSAC) that runs in your browser. That means you should save the edited JSON with the Save button. Run the AppLSAC Firefox and create the