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(
    value={
        "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
value 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 value trait — change something in the UI and the new value becomes visible from Python.

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

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.1.0.tar.gz (112.4 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.1.0-py3-none-any.whl (97.5 kB view details)

Uploaded Python 3

File details

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

File metadata

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

File hashes

Hashes for anyjsonviewer-0.1.0.tar.gz
Algorithm Hash digest
SHA256 b36efe5b76a9e1c9463b9f9374d6d6e5de92565dfa2325e60f56a249c063328a
MD5 444f77eb4df655fe1320cb278edcb846
BLAKE2b-256 951ba6121251259d47e1bf2fad95ef3dd663ab743122c806fe2313c8089ef5da

See more details on using hashes here.

Provenance

The following attestation bundles were made for anyjsonviewer-0.1.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.1.0-py3-none-any.whl.

File metadata

  • Download URL: anyjsonviewer-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 97.5 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.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 cfd2c2ea5dd61deacb3503a602335acd0e061c634e201e5bb67a0a96fb07e741
MD5 9ad1af1d1a93516c21c56d81c53b4da3
BLAKE2b-256 9393f2ce3388bdbfe8d5fa22ac96be402ad9aaad41d752a8422e2666582fa2f5

See more details on using hashes here.

Provenance

The following attestation bundles were made for anyjsonviewer-0.1.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