2016-01-11 22:44:03 +08:00
|
|
|
<!DOCTYPE HTML>
|
2020-09-23 16:23:38 +08:00
|
|
|
<html lang="en">
|
2016-01-11 22:44:03 +08:00
|
|
|
<head>
|
2020-09-23 16:23:38 +08:00
|
|
|
<meta charset="utf-8">
|
2016-01-11 22:44:03 +08:00
|
|
|
|
|
|
|
<link href="../dist/jsoneditor.css" rel="stylesheet" type="text/css">
|
|
|
|
<script src="../dist/jsoneditor.js"></script>
|
|
|
|
|
|
|
|
<style type="text/css">
|
|
|
|
body {
|
|
|
|
font: 10.5pt arial;
|
|
|
|
color: #4d4d4d;
|
|
|
|
line-height: 150%;
|
2019-07-24 17:00:49 +08:00
|
|
|
width: 600px;
|
2016-01-11 22:44:03 +08:00
|
|
|
padding-left: 40px;
|
|
|
|
}
|
|
|
|
|
2019-09-11 21:59:19 +08:00
|
|
|
html, body {
|
|
|
|
width: 100%;
|
|
|
|
padding: 0;
|
|
|
|
box-sizing: border-box;
|
|
|
|
}
|
|
|
|
|
2016-01-11 22:44:03 +08:00
|
|
|
code {
|
|
|
|
background-color: #f5f5f5;
|
|
|
|
}
|
|
|
|
|
|
|
|
#jsoneditor {
|
2019-09-11 21:59:19 +08:00
|
|
|
max-width: 600px;
|
|
|
|
width: 90%;
|
2016-01-11 22:44:03 +08:00
|
|
|
height: 500px;
|
|
|
|
}
|
|
|
|
</style>
|
|
|
|
</head>
|
|
|
|
<body>
|
|
|
|
|
|
|
|
<p>
|
|
|
|
Switch editor mode using the mode box.
|
|
|
|
Note that the mode can be changed programmatically as well using the method
|
|
|
|
<code>editor.setMode(mode)</code>, try it in the console of your browser.
|
|
|
|
</p>
|
|
|
|
|
|
|
|
<div id="jsoneditor"></div>
|
|
|
|
|
|
|
|
<script>
|
|
|
|
var container = document.getElementById('jsoneditor');
|
|
|
|
|
|
|
|
var schema = {
|
2019-06-12 21:43:16 +08:00
|
|
|
"title": "User",
|
2016-01-11 22:44:03 +08:00
|
|
|
"type": "object",
|
|
|
|
"properties": {
|
|
|
|
"firstName": {
|
|
|
|
"type": "string"
|
|
|
|
},
|
|
|
|
"lastName": {
|
|
|
|
"type": "string"
|
|
|
|
},
|
2016-01-15 03:04:45 +08:00
|
|
|
"gender": {
|
|
|
|
"enum": ["male", "female"]
|
|
|
|
},
|
2016-01-11 22:44:03 +08:00
|
|
|
"age": {
|
|
|
|
"description": "Age in years",
|
2019-03-08 03:50:05 +08:00
|
|
|
"examples": [18, 65],
|
2016-01-11 22:44:03 +08:00
|
|
|
"type": "integer",
|
|
|
|
"minimum": 0
|
|
|
|
},
|
|
|
|
"hobbies": {
|
2017-07-05 05:28:28 +08:00
|
|
|
"$ref": "hobbies.json"
|
2016-01-11 22:44:03 +08:00
|
|
|
}
|
|
|
|
},
|
|
|
|
"required": ["firstName", "lastName"]
|
|
|
|
};
|
|
|
|
|
2017-07-05 05:28:28 +08:00
|
|
|
var hobbiesSchema = {
|
|
|
|
"type": "array",
|
|
|
|
"items": {
|
|
|
|
"type": "string"
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2016-01-11 22:44:03 +08:00
|
|
|
var options = {
|
2016-01-13 03:18:56 +08:00
|
|
|
mode: 'tree',
|
2019-07-09 02:00:34 +08:00
|
|
|
modes: ['code', 'form', 'text', 'tree', 'view', 'preview'], // allowed modes
|
2016-01-11 22:44:03 +08:00
|
|
|
onError: function (err) {
|
|
|
|
console.error(err);
|
|
|
|
},
|
2017-07-05 05:28:28 +08:00
|
|
|
schema: schema,
|
|
|
|
schemaRefs: {"hobbies.json": hobbiesSchema}
|
2016-01-11 22:44:03 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
var json = {
|
|
|
|
"firstName": "Jos",
|
|
|
|
"lastName": "de Jong",
|
2016-01-15 03:04:45 +08:00
|
|
|
gender: null,
|
2016-01-11 22:44:03 +08:00
|
|
|
"age": 34.2,
|
|
|
|
"hobbies": [
|
|
|
|
"programming",
|
|
|
|
"movies",
|
|
|
|
"bicycling"
|
|
|
|
]
|
|
|
|
};
|
|
|
|
|
|
|
|
var editor = new JSONEditor(container, options, json);
|
|
|
|
|
|
|
|
console.log('json', json);
|
|
|
|
console.log('schema', schema);
|
|
|
|
</script>
|
|
|
|
</body>
|
|
|
|
</html>
|