Exploring the JSON Rich Text Editor
Contentstack’s Rich Text Editor offers a powerful, customizable interface for content editors, backed by robust developer features that allow complete control over the HTML output.
Key Features for Content Editors
-
Rich media embedding (images, videos, tables)
-
Integration with external systems (e.g., Cloudinary)
-
AI-assisted content enhancements
-
Embedding and linking other content entries
Configuring the Rich Text Field
Basic Configuration
-
Inline formatting: Bold, Italic, Underline
-
Block formatting: Headers, Paragraphs
Advanced Configuration
-
Includes rich media, tables, and embeds
Custom Configuration
-
Selectively enable or disable features
-
Useful for restricting options for SEO or accessibility purposes (e.g., avoiding multiple H1 tags)
Embedding and External References
-
Entries: Embed full entries directly within Rich Text.
-
Assets: Embed images or videos directly, either from internal assets or external systems like Cloudinary.
Customizing HTML Output
The Rich Text Editor outputs structured JSON, which developers can convert into customized HTML using the Contentstack Delivery SDK utility functions.
JSON Structure
-
Rich Text content is stored as JSON with clear semantic descriptions.
-
Example JSON snippet:
{
"type": "paragraph",
"children": [
{ "text": "Rich", "italic": true },
{ "text": " text editor", "bold": true }
]
}
Converting JSON to HTML
Use the built-in utility function:
import { jsonToHtml } from '@contentstack/utils';
const htmlOutput = jsonToHtml(entry.content);
Customizing Rendered HTML
Customize the output further with render options:
const renderOptions = {
p: (node, next) => (node.children[0].text.trim() === '' ? '' : `<p>${next(node.children)}</p>`),
a: (node, next) => `<a href="${node.attrs.href}" rel="noopener nofollow">${next(node.children)}</a>`
};
const htmlOutput = jsonToHtml(entry.content, renderOptions);
Example Use Cases
-
Remove empty paragraphs to keep markup clean.
-
Add SEO-friendly attributes to links automatically.
-
Customize image rendering for optimal performance (lazy loading, image optimization).
Handling Embedded Entries and Assets
Embedded Entries
When referencing another entry:
const renderOptions = {
embedded_entry: (node) => `<div class="embedded-entry">${node.entry.title}</div>`
};
Cloudinary Assets
Customize Cloudinary images dynamically:
const renderOptions = {
cloudinary: (node) => `<img src="${node.attrs.secure_url}" alt="${node.attrs.alt}" loading="lazy">`
};
Advanced Image Customization
Add dynamic parameters to Cloudinary images:
function customCloudinaryImage(asset, metadata) {
const params = 'w_800,h_450,f_auto,q_90,c_fill';
return `<img src="${asset.url}?${params}" alt="${asset.alt}" loading="lazy">`;
}
Best Practices
-
Clearly separate editorial content input from HTML rendering.
-
Allow content editors freedom within the Rich Text editor, and handle all necessary cleanup in the rendering logic.
-
Use JSON rendering hooks to avoid manual HTML adjustments by editors.
Resources
Related Content

APIs and Developer Tooling
Course1h 36m 25s
Preview, Visual Builder, and Releases
Course1h 2m 25s
CMS Developer Orientation
Course23m 30s
Integrations and the Composable DXP
Course41m 15s
Content Modeling
Course1h 20m 35s
Extending and Customizing Contentstack
Course58m 30s
CMS Developer Foundations
Course32m 30s
Workflow, Branches, and Collaboration
Course48m 45s
Agent OS Foundations
Course26m 40s
Understanding Assets
Explainer4m 41s
Contentstack Assets Foundations
Course39m 32s
Live Preview: Editing with Confidence
Explainer2m 3s
Understanding Content Versions
Explainer3m 28s
Understanding Localization
Explainer3m 58sProject Managing a Contentstack Implementation
Course37m 56s