Skip to content

JSON-LD

A page's structured data as one ld+json script from a value, escaped and set through Trusted Types.

<p>The page below carries an Article node for "Spring update" by Alex Rivera. A data block is never drawn; its text, as the browser parsed it:</p>
<div data-mount="node"></div>
<pre class="cap-mono" id="read-node"></pre>

Installation

// package.json: "capsomer": "github:DrDustinEdwards/capsomer#v0.152.2"
import "capsomer/tokens.css";
import "capsomer/base.css";

Usage

<script type="application/ld+json">{"@context":"https://schema.org","@type":"Article","headline":"Spring update"}</script>

Examples

A list whose strings hold markup and line separators

<p>A title that holds <code>&lt;/script&gt;</code>, <code>&amp;</code> and U+2028 stays inside the block and parses back unchanged.</p>
<div data-mount="hostile"></div>
<pre class="cap-mono" id="read-hostile"></pre>

API reference

JsonLd

PropTypeRequiredDoes
dataunknownYesA schema.org node, or a list of nodes (one block, a JSON array). Plain data only: it is serialized as JSON, so a function or undefined is dropped as JSON.stringify drops it.

Accessibility

KeyDoes
NoneA data block is not drawn

Nothing is drawn and nothing is read: the user agent hides every script element.