JSONSerializer
@blobs/sdk / serializers / JSONSerializer
Defined in: serializers/JSONSerializer.ts:18
Serializer that converts JSON content to and from HTML for editing.
toHTML formats and syntax-highlights the JSON for display inside a
contenteditable element; toContent strips the highlight markup, parses
the result, and re-emits a canonically-indented JSON string so the round
trip preserves structure. Invalid JSON is preserved as-is so users can
edit mid-typing without the serializer destroying partial input.
Extends
Constructors
Constructor
new JSONSerializer(
config?):JSONSerializer
Defined in: serializers/JSONSerializer.ts:27
Parameters
config?
Optional SerializerConfig overrides.
Returns
JSONSerializer
Overrides
Properties
config
protectedconfig:SerializerConfig
Defined in: serializers/BaseSerializer.ts:35
Effective configuration (defaults merged with constructor overrides).
Inherited from
format
readonlyformat:ContentFormat='json'
Defined in: serializers/JSONSerializer.ts:19
The content format this serializer handles.
Overrides
Methods
configure()
configure(
config):void
Defined in: serializers/BaseSerializer.ts:62
Merges new options into the current configuration.
Parameters
config
Partial config to apply.
Returns
void
Inherited from
getConfig()
getConfig():
SerializerConfig
Defined in: serializers/BaseSerializer.ts:69
Returns a defensive copy of the current configuration.
Returns
Inherited from
escapeHTML()
protectedescapeHTML(text):string
Defined in: serializers/BaseSerializer.ts:76
Escape HTML special characters
Parameters
text
string
Returns
string
Inherited from
unescapeHTML()
protectedunescapeHTML(html):string
Defined in: serializers/BaseSerializer.ts:90
Unescape HTML entities back to characters
Parameters
html
string
Returns
string
Inherited from
createLineBreak()
protectedcreateLineBreak():string
Defined in: serializers/BaseSerializer.ts:105
Create a line break element based on config
Returns
string
Inherited from
BaseSerializer.createLineBreak
wrapParagraph()
protectedwrapParagraph(content,className?):string
Defined in: serializers/BaseSerializer.ts:116
Create a paragraph wrapper
Parameters
content
string
className?
string
Returns
string
Inherited from
stripTags()
protectedstripTags(html):string
Defined in: serializers/BaseSerializer.ts:124
Strip all HTML tags from a string
Parameters
html
string
Returns
string
Inherited from
normalizeWhitespace()
protectednormalizeWhitespace(text):string
Defined in: serializers/BaseSerializer.ts:131
Normalize whitespace in content
Parameters
text
string
Returns
string
Inherited from
BaseSerializer.normalizeWhitespace
divBreaksToNewlines()
protecteddivBreaksToNewlines(html):string
Defined in: serializers/BaseSerializer.ts:141
Convert contenteditable div breaks to newlines
Parameters
html
string
Returns
string
Inherited from
BaseSerializer.divBreaksToNewlines
parseHTML()
protectedparseHTML(html):string
Defined in: serializers/BaseSerializer.ts:161
Parse HTML using DOMParser if available, fallback to regex
Parameters
html
string
Returns
string
Inherited from
toContent()
toContent(
html):ParsedContent
Defined in: serializers/JSONSerializer.ts:41
Strips syntax-highlight markup from contenteditable HTML and returns a canonically-indented JSON string. Falls back to the raw text when the input is not valid JSON.
Parameters
html
string
HTML emitted by the editor.
Returns
Overrides
toHTML()
toHTML(
content):RenderedHTML
Defined in: serializers/JSONSerializer.ts:78
Renders a JSON string into HTML with syntax highlighting wrapped in a configurable container. Invalid JSON is rendered unchanged so the editor can still display it.
Parameters
content
string
JSON content to render.