2016-01-11 22:44:03 +08:00
|
|
|
<!DOCTYPE HTML>
|
|
|
|
<html>
|
|
|
|
<head>
|
|
|
|
<meta http-equiv="Content-Type" content="text/html;charset=utf-8">
|
|
|
|
|
|
|
|
<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%;
|
|
|
|
width: 500px;
|
|
|
|
padding-left: 40px;
|
|
|
|
}
|
|
|
|
|
|
|
|
code {
|
|
|
|
background-color: #f5f5f5;
|
|
|
|
}
|
|
|
|
|
|
|
|
#jsoneditor {
|
2018-08-25 21:31:58 +08:00
|
|
|
width: 500px;
|
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 = {
|
|
|
|
"title": "Example Schema",
|
|
|
|
"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',
|
2016-01-12 20:16:13 +08:00
|
|
|
modes: ['code', 'form', 'text', 'tree', 'view'], // 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>
|