<json-viewer>

A dependency-free Web Component for rendering any JS value as a collapsible tree. Path/glob API, source-data search, correct Map/Set handling, and a CSS-tokens theme contract.

Features

Quick Start

Install

npm install @profpowell/json-viewer

Or include the built module directly in any HTML page:

<script type="module" src="https://unpkg.com/@profpowell/json-viewer"></script>

Basic usage

<json-viewer expanded="2" show-sizes></json-viewer>
<script type="module">
  import '@profpowell/json-viewer'
  document.querySelector('json-viewer').data = await fetch('/api').then(r => r.json())
</script>

Programmatic API

const v = document.querySelector('json-viewer')
v.expand('users[*].name')          // glob
v.search('error', { regex: true }) // iterator with next/prev/current/count
v.entryAt('cache@0')               // { key, value } — preserves Map key identity
await v.copy()                     // BigInt-safe full snapshot to clipboard

Related Components

Part of the ProfPowell vanilla web components suite: