Last active
June 5, 2021 08:51
-
-
Save vitran96/609d9758c60d4009be7ce415b5e721f3 to your computer and use it in GitHub Desktop.
JSON-Editor usage example
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const SCHEMA_EXAMPLE = { | |
"$schema": "https://json-schema.org/draft/2020-12/schema", | |
"$id": "https://example.com/product.schema.json", | |
"title": "Product", | |
"description": "A product from Acme's catalog", | |
"type": "object", | |
"properties": { | |
"productId": { | |
"description": "The unique identifier for a product", | |
"type": "integer" | |
}, | |
"productName": { | |
"description": "Name of the product", | |
"type": "string" | |
}, | |
"receiveDate": { | |
"description": "Received date", | |
"type": "string" | |
} | |
}, | |
"required": ["productId", "productName"] | |
} | |
const BOOLEAN_CONFIG = { | |
"required_by_default": false, | |
"display_required_only": false, | |
"show_opt_in": true, | |
"no_additional_properties": false, | |
"ajax": false, | |
"disable_edit_json": false, | |
"disable_collapse": false, | |
"disable_properties": false, | |
"disable_array_add": false, | |
"disable_array_reorder": false, | |
"disable_array_delete": false, | |
"enable_array_copy": true, | |
"array_controls_top": false, | |
"disable_array_delete_all_rows": false, | |
"disable_array_delete_last_row": false | |
} | |
// This might not needed | |
const THEMES = { | |
"barebones":"", | |
"bootstrap3":"", | |
"bootstrap4":"", | |
"html":"", | |
"spectre":"", | |
"tailwind":"" | |
} | |
// EXTERNAL LIBRARY -> not needed |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!DOCTYPE html> | |
<html lang="en"> | |
<head> | |
<meta charset="utf-8" /> | |
<title>JSON Editor - test</title> | |
<link rel='stylesheet' href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/css/bootstrap.min.css"> | |
<link rel='stylesheet' href="https://use.fontawesome.com/releases/v5.6.1/css/all.css"> | |
</head> | |
<body> | |
<div id="json-editor-form"></div> | |
<script src="https://cdn.jsdelivr.net/npm/@json-editor/json-editor@latest/dist/jsoneditor.min.js"></script> | |
<script src="https://cdn.jsdelivr.net/npm/lz-string@1.4.4/libs/lz-string.min.js"></script> | |
<script src="./scripts/constants.js"></script> | |
<script src="./scripts/script.js"></script> | |
</body> | |
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// var data = {} | |
var defaultOptions = { | |
iconlib: 'fontawesome5', | |
object_layout: 'normal', | |
schema: SCHEMA_EXAMPLE, | |
show_errors: 'interaction', | |
theme: 'bootstrap4', | |
show_opt_in: true, | |
enable_array_copy: true, | |
ajax: true | |
} | |
var jsoneditor = null | |
var jsonEditorForm = document.querySelector('#json-editor-form') | |
jsoneditor = new window.JSONEditor(jsonEditorForm, defaultOptions) | |
// jsoneditor.setValue(json_example) | |
// jsoneditor.on('change', function () { | |
// // output | |
// var json = jsoneditor.getValue() | |
// outputTextarea.value = JSON.stringify(json, null, 2) | |
// // validate | |
// var validationErrors = jsoneditor.validate() | |
// if (validationErrors.length) { | |
// validateTextarea.value = JSON.stringify(validationErrors, null, 2) | |
// } else { | |
// validateTextarea.value = 'valid' | |
// } | |
// }) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment