Skip to main content

Budget‑constrained JSON preview renderer (Python bindings)

Project description

headson

Head/tail for JSON — but structure‑aware. Get a compact preview that shows both the shape and representative values of your data, all within a strict character budget.

Available as:

Install

Using Cargo:

cargo install headson

From source:

cargo build --release
target/release/headson --help

Features

  • Budgeted output: specify exactly how much JSON you want to see
  • Multiple output formats : json (machine‑readable), pseudo (human‑friendly), js (valid JavaScript, most detailed metadata).
  • Multiple inputs: preview many files at once with a shared or per‑file budget.
  • Fast: can process gigabyte-scale files in seconds (mostly disk-constrained)
  • Available as a CLI app and as a Python library

Fits into command line workflows

If you’re comfortable with tools like head and tail, use headson when you want a quick, structured peek into a JSON file without dumping the entire thing.

  • head/tail operate on bytes/lines - their output is not optimized for tree structures
  • jq you need to craft filters to preview large JSON files
  • headson is like head/tail for trees: zero config but it keeps structure and represents content as much as possible

Usage

headson [FLAGS] [INPUT...]
  • INPUT (optional, repeatable): file path(s). If omitted, reads JSON from stdin. Multiple input files are supported.
  • Prints the preview to stdout. On parse errors, exits non‑zero and prints an error to stderr.

Common flags:

  • -n, --budget <BYTES>: per‑file output budget. When multiple input files are provided, the total budget equals <BYTES> * number_of_inputs.
  • -N, --global-budget <BYTES>: total output budget across all inputs. Useful when you want a fixed-size preview across many files (may omit entire files). Mutually exclusive with --budget.
  • -f, --template <json|pseudo|js>: output style (default: pseudo)
  • -m, --compact: no indentation, no spaces, no newlines
  • --no-newline: single line output
  • --no-space: no space after : in objects
  • --indent <STR>: indentation unit (default: two spaces)
  • --string-cap <N>: max graphemes to consider per string (default: 500)
  • --tail: prefer the end of arrays when truncating. Strings are unaffected. In pseudo/js templates the omission marker appears at the start; json remains strict JSON with no annotations.

Notes:

  • With multiple input files:
    • JSON template outputs a single JSON object keyed by the input file paths.
    • Pseudo and JS templates render file sections with human-readable headers.
    • Using --global-budget may truncate or omit entire files to respect the total budget.
    • The tool finds the largest preview that fits the budget; if even the tiniest preview exceeds it, you still get a minimal, valid preview.
    • When passing file paths, directories and binary files are ignored; a notice is printed to stderr for each (e.g., Ignored binary file: ./path/to/file). Stdin mode reads the stream as-is.

Quick one‑liners:

  • Peek a big JSON stream (keeps structure):

    zstdcat huge.json.zst | headson -n 800 -f pseudo
    
  • Many files with a fixed overall size:

    headson -N 1200 -f json logs/*.json
    
  • Glance at a file, JavaScript‑style comments for omissions:

    headson -n 400 -f js data.json
    

Show help:

headson --help

Examples: head vs headson

Input:

{"users":[{"id":1,"name":"Ana","roles":["admin","dev"]},{"id":2,"name":"Bo"}],"meta":{"count":2,"source":"db"}}

Naive cut (can break mid‑token):

jq -c . users.json | head -c 80
# {"users":[{"id":1,"name":"Ana","roles":["admin","dev"]},{"id":2,"name":"Bo"}],"me

Structured preview with headson (pseudo):

headson -n 120 -f pseudo users.json
# {
#   users: [
#     { id: 1, name: "Ana", roles: [ "admin", … ] },
#     …
#   ]
#   meta: { count: 2, … }
# }

Machine‑readable preview (json):

headson -n 120 -f json users.json
# {"users":[{"id":1,"name":"Ana","roles":["admin"]}],"meta":{"count":2}}

Python Bindings

A thin Python extension module is available on PyPI as headson.

  • Install: pip install headson (prebuilt wheels for CPython 3.10–3.12 on Linux/macOS/Windows). Older/newer Python versions may build from source if Rust is installed.
  • API:
    • headson.summarize(text: str, *, template: str = "pseudo", character_budget: int | None = None, tail: bool = False) -> str
      • template: one of "json" | "pseudo" | "js"
      • character_budget: maximum output size in characters (default: 500)
      • tail: prefer the end of arrays when truncating; strings unaffected. Affects only display templates (pseudo/js); json remains strict.

Example:

import json
import headson

data = {"foo": [1, 2, 3], "bar": {"x": "y"}}
preview = headson.summarize(json.dumps(data), template="json", character_budget=200)
print(preview)

# Prefer the tail of arrays (annotations show in pseudo/js only)
print(
    headson.summarize(
        json.dumps(list(range(100))),
        template="pseudo",
        character_budget=80,
        tail=True,
    )
)

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

headson-0.3.0.tar.gz (35.4 kB view details)

Uploaded Source

Built Distributions

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

headson-0.3.0-cp312-cp312-win_amd64.whl (221.5 kB view details)

Uploaded CPython 3.12Windows x86-64

headson-0.3.0-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (328.6 kB view details)

Uploaded CPython 3.12manylinux: glibc 2.17+ x86-64

headson-0.3.0-cp312-cp312-macosx_11_0_arm64.whl (282.0 kB view details)

Uploaded CPython 3.12macOS 11.0+ ARM64

headson-0.3.0-cp311-cp311-win_amd64.whl (224.2 kB view details)

Uploaded CPython 3.11Windows x86-64

headson-0.3.0-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (331.7 kB view details)

Uploaded CPython 3.11manylinux: glibc 2.17+ x86-64

headson-0.3.0-cp311-cp311-macosx_11_0_arm64.whl (283.3 kB view details)

Uploaded CPython 3.11macOS 11.0+ ARM64

headson-0.3.0-cp310-cp310-win_amd64.whl (223.9 kB view details)

Uploaded CPython 3.10Windows x86-64

headson-0.3.0-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (331.5 kB view details)

Uploaded CPython 3.10manylinux: glibc 2.17+ x86-64

headson-0.3.0-cp310-cp310-macosx_11_0_arm64.whl (283.2 kB view details)

Uploaded CPython 3.10macOS 11.0+ ARM64

File details

Details for the file headson-0.3.0.tar.gz.

File metadata

  • Download URL: headson-0.3.0.tar.gz
  • Upload date:
  • Size: 35.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: maturin/1.9.6

File hashes

Hashes for headson-0.3.0.tar.gz
Algorithm Hash digest
SHA256 a8ab1c99dfe08ebf741f2ce68fa0390a48c87d7c4b81eb448974f17a3ececa33
MD5 5e1b04dbcb363b5cc5c3d234f9aa2a81
BLAKE2b-256 9e37bdbd11daee322e71458f9acedd2107c721ba6a3551d2664346d9a2789fc0

See more details on using hashes here.

File details

Details for the file headson-0.3.0-cp312-cp312-win_amd64.whl.

File metadata

  • Download URL: headson-0.3.0-cp312-cp312-win_amd64.whl
  • Upload date:
  • Size: 221.5 kB
  • Tags: CPython 3.12, Windows x86-64
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: maturin/1.9.6

File hashes

Hashes for headson-0.3.0-cp312-cp312-win_amd64.whl
Algorithm Hash digest
SHA256 24430129e6731f487ee91c6321472e213a2e5254e2d22e24e61cd09878259f8e
MD5 bbb4e698075279771df71eb32c475b4d
BLAKE2b-256 1c46dd468e20edba40a3cb45cc74c0c7277806169f629cc152ecf9d2cf86c908

See more details on using hashes here.

File details

Details for the file headson-0.3.0-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for headson-0.3.0-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 ec48410fe5b7f6227c13f1fba662e56fd791b7d092482de28dd5e5ff945b37f0
MD5 14e42afdd5adfabdf1c5ce5a080b1a1d
BLAKE2b-256 c21994e3794acd1da90fab47a2330c1c9e0db5726e9acee6cb92a399b7c492cd

See more details on using hashes here.

File details

Details for the file headson-0.3.0-cp312-cp312-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for headson-0.3.0-cp312-cp312-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 1ef63a1905b31104e1e410e892dba14b3a745c3fc53e7f1f11afb0af4272ed64
MD5 0dc6f85b7e8a128a57b97e7ba68e5740
BLAKE2b-256 7f19e8c2f50b6168b230f0e9a9939a91d919a6791ff2f175fe133de3f495ba1e

See more details on using hashes here.

File details

Details for the file headson-0.3.0-cp311-cp311-win_amd64.whl.

File metadata

  • Download URL: headson-0.3.0-cp311-cp311-win_amd64.whl
  • Upload date:
  • Size: 224.2 kB
  • Tags: CPython 3.11, Windows x86-64
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: maturin/1.9.6

File hashes

Hashes for headson-0.3.0-cp311-cp311-win_amd64.whl
Algorithm Hash digest
SHA256 ba1d46bee1355f565dee512f1c3d993bbebd02367e42dc3db6d92a561f9e5c54
MD5 398540b9a131be8365cc197b3b473dff
BLAKE2b-256 65345a32f6bcd6e02b888dea4cb9e3e5873126b9a1e52cb3432192c8c712c0ed

See more details on using hashes here.

File details

Details for the file headson-0.3.0-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for headson-0.3.0-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 b6ace8e35993631752a8b90c3dd46b7b50f6e1a6bf7eb3903f5c56741040195a
MD5 2272ed68e19bb379ef842a898d8e47fd
BLAKE2b-256 adc554e285a13dd1a867e645e086b62069d19b32a8b848603402eabeaafef56e

See more details on using hashes here.

File details

Details for the file headson-0.3.0-cp311-cp311-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for headson-0.3.0-cp311-cp311-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 3c130fe45f4df8f390c9e517bedc9b3b985fdcac8b2f0a44da5361b2f7ec1f62
MD5 51b30419b51fdc5c14f762e6df1d9db8
BLAKE2b-256 f6b994b8c7fac158ecaf09ee9fbdd511f24714a22086b45aadd44ce0158f9251

See more details on using hashes here.

File details

Details for the file headson-0.3.0-cp310-cp310-win_amd64.whl.

File metadata

  • Download URL: headson-0.3.0-cp310-cp310-win_amd64.whl
  • Upload date:
  • Size: 223.9 kB
  • Tags: CPython 3.10, Windows x86-64
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: maturin/1.9.6

File hashes

Hashes for headson-0.3.0-cp310-cp310-win_amd64.whl
Algorithm Hash digest
SHA256 fec5fdc7f4506d079f3af482d3c680658b89bfcee4233edfad2945bfc50b75bb
MD5 53ae99715139b47cc9cffac9c238dbae
BLAKE2b-256 7fe0302f72b858a6b95c804a48137814d965aa7d79614fd2a635822a40a99bb3

See more details on using hashes here.

File details

Details for the file headson-0.3.0-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for headson-0.3.0-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 47b3f612fbc3dcf7e5eeb6d2a798d3131ade396aa52eb6ded0336fb5021e83ec
MD5 10f65add420ff26f47aecebe8ed2c150
BLAKE2b-256 707bbf4f6a4399bfb42e7c262d4526950731d6f4722414fc65cac444162d2dac

See more details on using hashes here.

File details

Details for the file headson-0.3.0-cp310-cp310-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for headson-0.3.0-cp310-cp310-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 9aca7e2e76cd08b807af0c81f1c1e86d474b86762375f2d7d594cd98bbab3d8f
MD5 b784ca68da6d706204ab7c8205e4560f
BLAKE2b-256 32533cd44c2191a7835776cfdb69f8de9f2e25ef661ed4dd5796175892f67260

See more details on using hashes here.

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