Skip to content

Json

The json directive can be used to render data as JSON into a template.

Type: json(data: any): Directive<Text>

INFO

json is a pure Text directive.

Using json

To use json, import it and insert the directive into a template.

ts
import { createComponent, json } from '@grainular/nord';

const component = createComponent((html) => {
    return html`<div>${json({ name: 'test' })}</div>`;
});

The json will be injected into the template at the specified place.

WARNING

As JSON Stringifying can fail, an error will be displayed if the value cannot be stringified.

Released under the MIT License.