Skip to content

API Reference parrot.tools.compression.codecs.json_compact

github-actions[bot] edited this page Nov 10, 2026 · 4 revisions

parrot.tools.compression.codecs.json_compact

View source

json_compact codec — MINIMAL-level, strictly lossless compression.

The default wildcard codec (see the core compressors.toml manifest): every unconfigured deployment gets this at FilterLevel.MINIMAL (G2). Because it is the zero-config baseline, the bar is losslessness, not aggressiveness — lossy is always False for this codec.

Honest calibration (spec Sec 7): BPE tokenizers merge whitespace runs, so expect roughly 5-15% token savings even when the byte diff looks larger. The real return on investment is in NORMAL (the columnar codec, TASK-1954).

Alias CompressionOutcome

Re-exported from parrot.tools.compression.protocol.CompressionOutcome.

Alias FilterLevel

Re-exported from parrot.tools.compression.levels.FilterLevel.

Class JsonCompactCodec

Lossless MINIMAL-level codec: separator compaction, null-key elision, and exact sibling dedup.

Three transformations, all strictly lossless:

  1. Separator compaction — serialized with (",", ":") separators, no indentation, no trailing whitespace (delegated to datamodel.parsers.json.json_encoder, the project serializer).
  2. Null-key elision — dict keys whose value is None are dropped, recursively. An all-null dict becomes {} rather than being dropped itself, preserving structure/arity at the parent level.
  3. Exact dedup — runs of 2+ structurally identical, consecutive list elements collapse to {"_repeat": N, "_value": <element>}. Applied only when the collapse is unambiguous and round-trippable.

Attributes:

Attribute Type Description
codec_name str

Method JsonCompactCodec.compress

Compress result at level. See class docstring.

compress(result: Any, *, level: FilterLevel, params: dict[str, Any]) -> CompressionOutcome

Parameter Type Default Description
result Any The unwrapped tool result payload.
level FilterLevel Effective :class:FilterLevel. NONE is a strict passthrough (same object, unchanged sizes).
params dict[str, Any] Codec params. Recognized key: dedup (bool, default True) — disable the exact-dedup transformation.

Returns: CompressionOutcome — class:CompressionOutcome with lossy always False.

Attribute logger

Alias register_codec

Re-exported from parrot.tools.compression.protocol.register_codec.

Architecture

Clients

Bots & Agents

Memory

Knowledge

Tools & Toolkits

Flows

Experts

Skills

Stores & Loaders

MCP & A2A

Server & APIs

Integrations

Outputs & A2UI

Prompts

Security

Operations

Migration

SDD Tooling

LLM Wiki

Deployment

Decisions

API Reference

Clone this wiki locally