This example shows how to set content as a JSON object. See the description of JSON view for more details. When the data is set in the editor, you can receive it in JSON or as HTML.
<!-- element -->
<textarea id="entry"></textarea>
<!-- call -->
<script>
let app = Redactor('#entry', {
data: {
"version": "1.0.0",
"time" : 1650860257872,
"blocks": [
{
"type": "heading",
"content": "...",
"level": 1
},
{
"type": "text",
"content": "..."
},
{
"type": "image",
"src": "/path-to-image.jpg",
"alt": "Alt text",
"caption": "..."
},
{
"type": "heading",
"content": "...",
"level": 2
},
{
"type": "text",
"content": "..."
}
]
}
});
function getJson(e) {
e.preventDefault();
console.log(app.editor.getJson())
}
function getContent(e) {
e.preventDefault();
console.log(app.editor.getContent(true))
}
</script>