Skip to main content

An anywidget wrapper for @textea/json-viewer

Project description

anyjsonviewer

An anywidget wrapper around @textea/json-viewer, giving you an interactive, collapsible JSON viewer inside Jupyter, JupyterLab, VS Code, Marimo, or any other frontend that supports Jupyter widgets.

Installation

pip install anyjsonviewer

Or with uv:

uv add anyjsonviewer

Usage

from anyjsonviewer import JsonViewer

JsonViewer(
    data={
        "name": "anyjsonviewer",
        "tags": ["json", "viewer", "anywidget"],
        "nested": {"count": 3, "ok": True},
    },
    theme="dark",
)

Traits

All props are synced traits, so you can update them from Python and the view re-renders live:

Trait Type Default Description
data any JSON-serializable None The data to display.
root_name str | None "root" Label for the root node. None hides it.
theme str "light" "light", "dark", or "auto".
class_name str | None None Custom CSS class on the root element.
style dict | None None Inline CSS styles for the root element.
indent_width int 3 Indentation width for nested objects.
default_inspect_depth int 5 Depth to auto-expand on first render. Set to 0 to fully collapse.
max_display_length int 30 Hide items in arrays/objects past this count.
group_arrays_after_length int 100 Group arrays into bracketed chunks after this length.
collapse_strings_after_length int 50 Truncate long strings; click to expand.
object_sort_keys bool False Sort object keys alphabetically.
quotes_on_keys bool True Wrap keys in quotes.
display_data_types bool True Show type annotations next to values.
display_size bool True Show length of arrays/objects.
display_comma bool True Show trailing commas.
highlight_updates bool True Briefly highlight values when they change.
enable_clipboard bool False Show copy-to-clipboard buttons.
enable_add bool False Show "add" buttons on objects/arrays.
enable_delete bool False Show "delete" buttons on items.
editable bool False Allow inline editing of values.

When editable, enable_add, or enable_delete are on, edits round-trip through the data trait — change something in the UI and the new value becomes visible from Python.

w = JsonViewer(data={"a": 1})
w.theme = "dark"         # live update
w.data = {"a": 1, "b": 2}

Using with Marimo

Marimo's mo.ui.anywidget() wrapper exposes .value as a dict of every synced trait, so to get just the JSON you'd write wrapper.value["data"]. You can also keep a reference to the underlying widget and use it directly:

viewer = JsonViewer(data=my_data)
ui = mo.ui.anywidget(viewer)
ui                  # render in a cell
viewer.data         # ← just the JSON, same as in Jupyter
ui.value["data"]    # ← Marimo wrapper-native equivalent

Development

The widget's JavaScript lives in js/index.jsx and is bundled with esbuild into src/anyjsonviewer/static/widget.js.

# Install Python deps
uv sync

# Install JS deps
npm install

# One-off build
npm run build

# Watch mode (pair with ANYWIDGET_HMR=1 in your notebook)
npm run dev

Building the wheel automatically runs the JS build via a custom Hatch hook:

uv build

To skip the JS build step (e.g. in CI where you've already built the bundle), set ANYJSONVIEWER_SKIP_JS_BUILD=1.

License

MIT

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

anyjsonviewer-0.2.0.tar.gz (114.3 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

anyjsonviewer-0.2.0-py3-none-any.whl (98.7 kB view details)

Uploaded Python 3

File details

Details for the file anyjsonviewer-0.2.0.tar.gz.

File metadata

  • Download URL: anyjsonviewer-0.2.0.tar.gz
  • Upload date:
  • Size: 114.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for anyjsonviewer-0.2.0.tar.gz
Algorithm Hash digest
SHA256 86054430a7ff60a5c516b8382475455ff10588b0462c9eee502b61ee195f4cfa
MD5 0824a821df757207ea6c3cf65e89df48
BLAKE2b-256 2d58bd8489af3217fa29ec2f8bc4f8cddd5f3364081df4d995a703c08b619b6c

See more details on using hashes here.

Provenance

The following attestation bundles were made for anyjsonviewer-0.2.0.tar.gz:

Publisher: release.yml on mluttikh/anyjsonviewer

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file anyjsonviewer-0.2.0-py3-none-any.whl.

File metadata

  • Download URL: anyjsonviewer-0.2.0-py3-none-any.whl
  • Upload date:
  • Size: 98.7 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for anyjsonviewer-0.2.0-py3-none-any.whl
Algorithm Hash digest
SHA256 d17d9c7a21b0836b34641fb40204449e6de84941af8d0585486822c5961e5c7b
MD5 5d43e648803333339fe99f7a148048e0
BLAKE2b-256 3ab12f6f4ea590037b9c31612759a12a537aa6f339ebc5e6fa5460ff590af5f9

See more details on using hashes here.

Provenance

The following attestation bundles were made for anyjsonviewer-0.2.0-py3-none-any.whl:

Publisher: release.yml on mluttikh/anyjsonviewer

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page