JSON Serialization
JSON is Lexical’s native serialization format, providing lossless conversion to and from EditorState.Exporting to JSON
Importing from JSON
React Example
JSON Structure
JSON serialization preserves the complete node tree:Markdown Serialization
The@lexical/markdown package provides Markdown import/export.
Setup
Exporting to Markdown
Importing from Markdown
Markdown Shortcuts Plugin
Enable Markdown shortcuts as you type:#for headings**text**for bold*text*for italic-for lists>for quotes
Available Transformers
packages/lexical-markdown/src/index.ts for complete API.
HTML Serialization
The@lexical/html package provides HTML import/export.
Setup
Exporting to HTML
Importing from HTML
Custom HTML Export
Control HTML export for custom nodes:Custom HTML Import
Handle HTML import for custom nodes:packages/lexical-html/src/index.ts for the complete API.
Copy & Paste
Lexical handles copy/paste automatically, using HTML as the primary format:Custom Paste Handling
Export on Copy
File Export
Export content to downloadable files:Best Practices
- JSON for Persistence: Use JSON for database storage (lossless)
- Markdown for Portability: Use Markdown for plain-text compatibility
- HTML for Web: Use HTML for web integration and email
- Custom Nodes: Implement
exportJSON(),importJSON(),exportDOM(), andimportDOM() - Version Control: Include version numbers in serialized data
- Validation: Validate imported data before parsing
- Error Handling: Wrap parsing in try-catch blocks
See Also
- API Reference: EditorState
- API Reference: Markdown Package
- API Reference: HTML Package
- Source:
packages/lexical-markdown/src/ - Source:
packages/lexical-html/src/