content-json
npx skills add https://github.com/crystallizeapi/ai --skill content-jsonCrystallize Rich Text Content JSON
You are generating rich text content in the Crystallize Content Transformer JSON format — a tree of nodes representing structured rich text (similar to an AST).
The output must be a JSON array of block nodes (or a single node object when used inline).
Node Structure
Every node has these properties:
| Property | Type | Required | Description |
|---|---|---|---|
kind |
"block" or "inline" |
yes | Block-level or inline |
type |
string or null |
yes | Semantic content type (see tables below) |
textContent |
string |
no | Raw text (leaf nodes only — mutually exclusive with children) |
children |
node[] |
no | Child nodes (mutually exclusive with textContent) |
metadata |
object |
no | Extra attributes (e.g. { "href": "..." } for links, { "id": "..." } for any element) |
A node is either a leaf (has textContent) or a branch (has children). Never set both.
Block Node Types (kind: "block")
type |
HTML equivalent | Notes |
|---|---|---|
"paragraph" |
<p> |
Most common block type |
"heading1" – "heading6" |
<h1> – <h6> |
|
"unordered-list" |
<ul> |
Children must be list-item |
"ordered-list" |
<ol> |
Children must be list-item |
"list-item" |
<li> |
|
"quote" |
<blockquote> |
Block quote. API html output writes it as <quote> |
"code" |
<code> |
Code block, inside preformatted. Inline code is the inline code node |
"preformatted" |
<pre> |
Preformatted text |
"table" |
<table> |
Contains table-row directly |
"table-row" |
<tr> |
Contains table-cell or table-head-cell |
"table-cell" |
<td> |
Contains block content (paragraph) |
"table-head-cell" |
<th> |
Contains block content (paragraph) |
"horizontal-line" |
<hr> |
Self-closing, no children/textContent needed |
"image" |
<img> |
Shows no image: API html output is an empty <img></img>, the React <ContentTransformer> renders nothing and the App drops the node. Use an images component or a paragraph’s images |
"container" |
<div> |
Generic block container |
"section" |
<section> |
|
"article" |
<article> |
|
"address" |
<address> |
|
"figure" |
<figure> |
|
"figcaption" |
<figcaption> |
|
"details" |
<details> |
|
"deleted" |
<del> |
Keep it inside a block such as paragraph: at the root the App cannot open the content |
"picture" |
<picture> |
|
"title-of-a-work" |
<cite> |
Inline Node Types (kind: "inline")
type |
HTML equivalent | Notes |
|---|---|---|
null |
(none) | Plain text wrapper — use textContent for raw text |
"strong" |
<strong> |
Bold |
"emphasized" |
<em> |
Italic |
"underlined" |
<u> |
|
"deleted" |
<del> |
Strikethrough, as the App writes it. API html output renders no tag |
"code" |
<code> |
Inline code, as the App writes it. API html output renders no tag |
"link" |
<a> |
Requires metadata.href. Optionally metadata.target and metadata.rel |
"highlight" |
<mark> |
|
"subscripted" |
<sub> |
|
"superscripted" |
<sup> |
|
"line-break" |
<br> |
Self-closing |
"abbrevition" |
<abbr> |
Note: this is the actual spelling used in the format |
"aside" |
<aside> |
|
"container" |
<span> |
Generic inline container |
"time" |
<time> |
Metadata
- Links (
type: "link"):{ "href": "https://...", "target": "_blank", "rel": "nofollow" }—href,targetandrelare supported. APIhtmloutput dropsrel; the App and the React<ContentTransformer>keep it. - Code blocks (
type: "code"):{ "language": "javascript" }— the App’s code language. APIhtmloutput does not render it. - All elements:
{ "id": "some-id" }— theidattribute is valid on every node. Only APIhtmloutput renders it, and the App drops it on save. - No other HTML attributes are supported in metadata.
Key Rules
- Text lives in leaf nodes only. A paragraph with mixed formatting contains inline children; those inline children hold the
textContent. A block with only plain text can carry it directly:{ "kind": "block", "type": "paragraph", "textContent": "Hello" }is what the App writes. - Plain text uses inline nodes with
type: null:{ "kind": "inline", "type": null, "textContent": "Hello" }. - Lists must follow:
unordered-list/ordered-list→list-item→ inline/block content. - Tables must follow:
table→table-row→table-cell/table-head-cell→paragraph→ inline content. Cells usekind: "block". A header is a first row oftable-head-cell.- Never emit
table-head,table-body,table-footerortable-caption: the Crystallize App editor drops them along with every row inside. When converting HTML, put the rows of<thead>/<tbody>/<tfoot>directly undertable, and turn a<caption>into a paragraph before the table.
- Never emit
- Nested formatting is done via
children: e.g. bold + italic =strongnode containing anemphasizedchild. - Top-level output is always an array of block nodes.
Strict Formatting Enforcement
These rules are mandatory — every generated or modified node must comply. Validate the output before returning it.
-
typeis always required. Every node must have an explicittypefield. For plain text inlines, use"type": null. Never omit it.- ❌
{ "kind": "inline", "textContent": "hello" } - ✅
{ "kind": "inline", "type": null, "textContent": "hello" }
- ❌
-
Formatting nodes (
strong,emphasized,underlined,subscripted,superscripted,deleted, inlinecode) hold one run of text, intextContentor through a single chain ofchildren. The App andhtmlinput write the first form below.- ✅
{ "kind": "inline", "type": "strong", "textContent": "bold text" } - ✅
{ "kind": "inline", "type": "strong", "children": [{ "kind": "inline", "type": null, "textContent": "bold text" }] } - ❌
{ "kind": "inline", "type": "strong", "children": [<text>, <text>] }: the App keeps only the last text, with every format applied to it. Emit sibling formatting nodes instead. - ❌ A
linkinside a formatting node: the App loses the link. Put the formatting inside thelink.
- ✅
-
No empty block nodes. Every block node must have either
children(with at least one child) ortextContent, excepthorizontal-line. Do not emit blocks like{ "kind": "block", "type": "paragraph" }with neither. -
Preserve existing structure. When the input already contains Crystallize JSON, preserve its formatting and structure. Do not restructure, re-wrap, or flatten nodes that are already valid.
- Tables saved by the Crystallize App editor have
kind: "inline"cells. Leave them as they are, but give new cellskind: "block": only block cells render as<td>/<th>in the API’s HTML output. - The App writes plain text nodes without
type, and an emptyparagraphfor a blank line. Leave those too.
- Tables saved by the Crystallize App editor have
-
codeblocks insidepreformattedusekind: "block"and hold the code intextContent, line breaks included. Give thepreformattednode notextContentof its own: the App drops it.
What the Crystallize App Keeps
The API stores any node, but the App’s rich text editor only knows part of the format. Anything else is missing when the field opens, and an edit in the App saves the field without it. For content that will be edited in the App, stay within these types:
- Blocks:
paragraph,heading1–heading6,unordered-list,ordered-list,list-item,quote,preformattedwithcode,table,table-row,table-cell,table-head-cell,horizontal-line. - Inline:
null,strong,emphasized,underlined,subscripted,superscripted,deleted,code,link,line-break.
The rest behaves like this:
- Other block types (
section,article,address,figure,figcaption,details,picture,image,title-of-a-work) are dropped with all their children. When converting HTML, lift the children out of these wrappers. containerandpreformattedare unwrapped: their children stay, buttextContenton a block-kind one is lost.- Other inline types (
highlight,abbrevition,aside,time) keep their text and lose the format when they usetextContent. Withchildrenthey are dropped, and so is atype: nullnode withchildren. - Content the App cannot open: inline children directly in a root-level block
containerorpreformatted, or adeletedblock at the root. The field shows “We aren’t able to display your rich text content due to an error in the data structure”, and a reset there erases the content. Fix it through the API instead.
Writing It to Crystallize
Rich text input is json, html, or both, each a list. It is the same on a richText component, a paragraph’s body and an image’s caption:
{ "componentId": "description", "richText": { "json": [{ "kind": "block", "type": "paragraph", "textContent": "Hello" }] }}jsonis not validated. The API only removes empty entries, so a wrongtypeor a misspelt property is stored without an error.isModelValidfrom the public@crystallize/content-transformerpackage checks types and properties. It does not check nesting, sotable-headpasses, and it rejects App-saved nodes withouttypeand the array entries described under Reading It Back.htmlis converted on write and stored asjson, after anyjsonsent with it. The package’sfromHTMLdoes the same conversion, so use it to preview the result. A string with one top-level element gives one node, and a string with several gives an array of nodes: send one string per block to keepjsonflat.- There is no Markdown input. Markdown sent in
htmlortextContentstays literal text, so convert it to nodes yourself. - A component’s
required,minandmaxare measured on the plain text of the JSON, so nodes without text count as empty.
The html conversion loses content. Send json for any of these:
In html |
What gets stored |
|---|---|
<table> |
Rows under a table-body, even with no <tbody> in the HTML (a <thead> becomes table-head), so the App drops them all. Discovery still serves them: see Reading It Back |
<blockquote> |
A type: null node, not quote, which the App drops if it wraps a <p>. Same for any tag the format does not map, such as <s> |
<div> |
container. With only text, the App loses the text. With inline content at the root, the App cannot open the field |
<pre> |
Line breaks are removed, so multi-line code becomes one line. Without an inner <code>, the App loses the text |
<img> |
image without src or alt |
| Attributes | Only id, and href and target on <a>, are kept |
Reading It Back
Rich text output on the Core and Catalogue APIs has json, html and plainText, with one html and one plainText string per json entry. On the Discovery API, a richText field and a paragraph’s body take format: json (the default), html or plainText, and html comes back as one string.
- A
jsonentry is a node or an array of nodes, the second fromhtmlinput with several top-level elements. Handle both when editing. Before rendering, flatten withjson.flat():<ContentTransformer>from@crystallize/reactjs-componentsrenders nothing for an array entry. - Discovery serves
html-written tables as semantic nodes. A<table>with<thead>and<tbody>, sent inhtml, comes back from Discovery withformat: jsonastable→table-head/table-body→table-row→table-head-cell/table-cell, and withformat: htmlas clean<table><thead>…<tbody>markup. So a storefront that reads Discovery can render or convert these tables (for example to Markdown) without loss. The App is the part that drops them: it expectstable-rowdirectly undertable(see Table with a header row and “What the Crystallize App Keeps”). Write tables ashtmlwhen only the storefront reads them, and as App-shapedjsonwhen editors will open the field. Lists come back asunordered-list/ordered-list/list-itemand bold asstrong. - Rich text inside a piece in a
componentMultipleChoicehas been reported to come back from Discovery as an array of arrays. A re-read on the same tenant (148 entries, 2026-11-12) gave one node per entry, so this is most likely the array-entry case above (several top-level elements in onehtmlstring). Flatten either way. Invalid crystallize-content-chunk:at the start of a Core APIhtmlorplainTextstring means thatjsonentry is malformed, for example atextContentthat is not a string.
Examples
Simple paragraph with bold text
[ { "kind": "block", "type": "paragraph", "children": [ { "kind": "inline", "type": null, "textContent": "This is " }, { "kind": "inline", "type": "strong", "children": [{ "kind": "inline", "type": null, "textContent": "bold" }] }, { "kind": "inline", "type": null, "textContent": " text." } ] }]Heading + paragraph with a link
[ { "kind": "block", "type": "heading2", "children": [{ "kind": "inline", "type": null, "textContent": "About Us" }] }, { "kind": "block", "type": "paragraph", "children": [ { "kind": "inline", "type": null, "textContent": "Visit " }, { "kind": "inline", "type": "link", "metadata": { "href": "https://example.com", "target": "_blank" }, "children": [{ "kind": "inline", "type": null, "textContent": "our site" }] }, { "kind": "inline", "type": null, "textContent": " for more." } ] }]Unordered list
[ { "kind": "block", "type": "unordered-list", "children": [ { "kind": "block", "type": "list-item", "children": [{ "kind": "inline", "type": null, "textContent": "First item" }] }, { "kind": "block", "type": "list-item", "children": [{ "kind": "inline", "type": null, "textContent": "Second item" }] } ] }]Table with a header row
[ { "kind": "block", "type": "table", "children": [ { "kind": "block", "type": "table-row", "children": [ { "kind": "block", "type": "table-head-cell", "children": [ { "kind": "block", "type": "paragraph", "children": [{ "kind": "inline", "type": null, "textContent": "Name" }] } ] }, { "kind": "block", "type": "table-head-cell", "children": [ { "kind": "block", "type": "paragraph", "children": [{ "kind": "inline", "type": null, "textContent": "Price" }] } ] } ] }, { "kind": "block", "type": "table-row", "children": [ { "kind": "block", "type": "table-cell", "children": [ { "kind": "block", "type": "paragraph", "children": [{ "kind": "inline", "type": null, "textContent": "Shoe" }] } ] }, { "kind": "block", "type": "table-cell", "children": [ { "kind": "block", "type": "paragraph", "children": [{ "kind": "inline", "type": null, "textContent": "42" }] } ] } ] } ] }]Code block
[ { "kind": "block", "type": "preformatted", "children": [ { "kind": "block", "type": "code", "textContent": "const a = 1;\nconst b = 2;", "metadata": { "language": "javascript" } } ] }]Bold + italic (nested inline formatting)
{ "kind": "inline", "type": "strong", "children": [ { "kind": "inline", "type": "emphasized", "children": [{ "kind": "inline", "type": null, "textContent": "bold and italic" }] } ]}
Crystallize AI