This file provides guidance to Claude Code (claude.ai/code) when working with code in this repository.
json-explorer is a CLI tool that reads a JSON Lines file (one JSON per line) and renders an interactive HTML page summarizing the structure, types, and value distributions across all the JSONs. It has zero runtime dependencies (stdlib only) and requires Python 3.10+.
The project uses Poetry 2 and a Makefile wrapper. The virtualenv lives in .venv (poetry.toml sets it in-project).
make install—poetry installplus pre-commit hook setup. Its final step,poetry shell, fails on Poetry 2 unless the shell plugin is installed; the install itself has already finished by then. Usepoetry run ...instead.make check—poetry check --lockandpre-commit run -a. Ruff is configured withfix = trueand black reformats, so this modifies files.make test—pytest --cov --cov-config=pyproject.toml --cov-report=xml.tox— runs the test suite on Python 3.10 and 3.11 (CI also runs this).make docs— serves mkdocs locally;make docs-testchecks the docs build with-s(strict).make build/make publish— build wheel / publish to PyPI. Publishing normally happens in CI: a published GitHub release sets the package version from the tag (pyproject.tomlstays at0.0.1), publishes, and deploys the docs.
Run a single test: poetry run pytest tests/test_explore.py::test_counts_simple.
Run the CLI during development: poetry run json-explorer --example (uses bundled json_explorer/example1.jsonl), or pass a .jsonl path. -n/--no-serve writes the HTML to stdout instead of starting the local HTTP server; -p/--port changes the port (default 8001).
Formatting: black's line length is 80, and that is what determines code layout. Ruff's 120 doesn't apply in practice because E501 is ignored.
The pipeline is: JSONL file → triples → tree → HTML.
TripleCounter is a dict subclass that aggregates information across many JSONs. For every node in every input JSON, iter_object yields a triple (path, type_name, value_or_length):
pathis a tuple of dict keys and theINDEXsentinel (used for list elements; rendered as[*]in JMESPath).type_nameis the Python type name ("dict","list","int","str","NoneType","bool","float").value_or_lengthis the scalar value for primitives, orlen()for dicts and lists.
These triples are bucketed into a nested structure: self[path][type_name] is a Counter mapping value_or_length → occurrences. This is what the counting tests in test_explore.py exercise directly — when modifying counting logic, those tests will tell you immediately if the structure invariant breaks.
TripleCounter.tree() walks the flat path → type → counter dict and builds a parent/child tree of Node objects by chopping the last element off each path. The root is the node whose path is the empty tuple. Node.html() recurses to emit the <ul>/<li> tree; Node.details_html() emits the <dialog> modal for each node. Each tree button names its modal in a data-dialog attribute, holding the dom_id that tree() generates, and a listener in template.html opens it. Don't use jmespath() as an id or put it in an inline handler: it comes from the input data. Anything from the input data, keys included, must be escaped before it reaches the HTML.
int and float are tracked separately while counting but merged into a synthetic "number" type at render time in both format_type and summary_html. The merge mutates the node's counters in place, and TYPE_TRANSLATE has a "number" entry but no "float" entry, so any new rendering path that looks up a type name has to merge first.
TripleCounter.html() reads template.html and style.css from the package directory and substitutes {{style}}, {{tree}}, and {{details}} placeholders (plain string replace — no template engine). The CSS and template are bundled into the wheel as package data, so changes to them take effect without code changes.
main() parses args, builds the TripleCounter, and renders the HTML once. It then either prints it (--no-serve) or starts an HTTPServer on localhost:<port> that returns the same pre-rendered page for every GET, whatever the path. A background thread waits on a threading.Event and opens the browser once the server is ready. Ctrl+C stops the server cleanly.
All tests are in tests/test_explore.py and use tests/data/example1.jsonl (identical to json_explorer/example1.jsonl) as the fixture. HTML output assertions parse with beautifulsoup4 (a dev dependency only). When adding new rendering logic, prefer asserting against the parsed soup over substring matching — see test_document_tree for the pattern.