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";import "capsomer/tokens.css";
import { JsonLd } from "capsomer/react/json-ld";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></script></code>, <code>&</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
| Prop | Type | Required | Does |
|---|---|---|---|
data | unknown | Yes | A 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
| Key | Does |
|---|---|
| None | A data block is not drawn |
Nothing is drawn and nothing is read: the user agent hides every script element.