Editors
Pretty Print JSON
Formatted, colored JSON, for showing data such as an API response, a payload or a settings object. It loads pretty-print-json on demand and follows the light and dark color scheme.
Nothing to show
Nothing to show
A spinner while the library loads, then the data indented in a <pre>, with keys, strings, numbers and booleans in different colors. Strings are shown as text: HTML inside them is never rendered.
JSON text #
The slot is parsed as JSON and formatted the same way; HTML entities in it are decoded first, so {{ $json }} works. Text that is not valid JSON is shown as it is, escaped.
Nothing to show
Library options #
options are passed to the library's toHtml(): indent, lineNumbers, linkUrls, quoteKeys, trailingCommas...
Nothing to show
Nothing to show
Line numbers and links #
lineNumbers numbers the lines and linkUrls turns the URLs in strings into links.
Nothing to show
Nothing to show
Events #
started, completed and failed fire on the wrapper and are listened to with the loadable: prefix.
Nothing to show
Nothing to show
Customization #
Classes go to the <pre>: limit its height and let it scroll for long payloads. The wrapper and spinner take the loadable: prefixes.
Nothing to show
Nothing to show
Reference
tk:pretty-print-json
| Prop | Type | Default | Description |
|---|---|---|---|
data |
mixed | null |
The data to show: an array, an object or a JSON string. When not given, the slot is used. |
options |
array | null |
Options for pretty-print-json's toHtml(). |
Slots
| Slot | Description |
|---|---|
| default | JSON text, when there is no data. |
Events
| Event | Detail | When |
|---|---|---|
started |
The library started loading. Not fired with loadable:silent. |
|
completed |
The library is loaded and the data is shown. | |
failed |
The library could not be loaded. |
Events
started, completed and failed are dispatched on the wrapper, do not bubble, and are listened to with the loadable: prefix: loadable:x-on:completed.
Customization
Classes and attributes on the tag go to the <pre>. The wrapper, spinner and error take the loadable: prefixes, as on tk:loadable.
Nothing to show
Accessibility
Plain text in a <pre>, read as written; the colors are only visual.
Behavior notes
- The library and its stylesheet are loaded from jsDelivr (
pretty-print-json@3) by the first block on the page. Whenwindow.prettyPrintJsonalready exists, nothing is requested, not even the stylesheet: importpretty-print-json/dist/css/pretty-print-json.csswith the library, or the data is shown without colors. - The colors switch with the
darkclass of<html>. - The data is formatted when the block is first rendered; a Livewire update that changes it does not format it again.