skillfed

compact-json

A JSON formatter that produces compact but human-readable

compact-json v1.8.2 1.1M downloads/30d#4,407 on PyPI41
Permissive license MIT AGING released

What it is and what it does

compact-json is a JSON formatter that balances readability with compactness by applying three formatting strategies: fitting simple objects and arrays onto a single line when they are short and not deeply nested, arranging complex lists across multiple lines with several items per line, or expanding each property or array item onto its own indented line. It exposes a Formatter class with configurable properties like max_inline_length, max_inline_complexity, and indent_spaces, allowing you to tune the output to your needs. It also provides a command-line utility for formatting JSON files directly from the shell.

The package is now deprecated and its maintainers explicitly recommend migrating to fractured-json, which tracks the upstream FracturedJson .NET project. Despite the deprecation notice, compact-json remains functional and receives occasional maintenance; it supports Python 3.9 through 3.14 and has no known security vulnerabilities. The three runtime dependencies are lightweight and widely available.

Use it for:

  • Format API responses or configuration files to a compact but readable form for logging or debugging without the verbosity of standard pretty-printing.
  • Reduce JSON file size while keeping the output human-readable for version control or data interchange.
  • Configure formatting rules (line length, nesting depth, indentation) to match your project's style guide or readability preferences.
  • Use the command-line tool in shell pipelines to format JSON from stdin or batch-process multiple JSON files with consistent settings.

Worth the install?

AI-flagged interpretation of the facts on this page — verify before relying

Formats JSON into compact, human-readable output by fitting objects and arrays onto single lines when they fit within configured length and complexity limits, falling back to multi-line formatting for larger structures.

Yes, if you need compact JSON formatting and can accept the aging maintenance status. The package is stable, has no known vulnerabilities, and works with current Python versions. However, the explicit deprecation notice and recommendation to migrate to fractured-json suggest this is a good time to evaluate whether that alternative better suits your long-term needs. Install only if you are comfortable with a package that receives infrequent updates.

Install

compact-json on PyPI

pip

pip install compact-json

uv

uv add compact-json

poetry

poetry add compact-json

Installing compact-json

Before you install

Low install friction with three lightweight runtime dependencies (wcwidth, setuptools, importlib-resources). Maintenance status is aging—last release was 231 days ago—but the package is not archived and the repository remains active with 41 stars.

License in practice

MIT license permits commercial and private use with minimal restrictions; you may use, modify, and distribute the package freely provided you retain the license notice.

Quickstart

import json
from compact_json import Formatter

formatter = Formatter()
formatter.indent_spaces = 2
formatter.max_inline_complexity = 10

with open("input.json", "r") as f:
    obj = json.load(f)
    json_string = formatter.serialize(obj)
    print(json_string)

Requires Python 3.9 or later (supports up to 3.14); package is deprecated and maintainers recommend migrating to fractured-json.

Verify before relying

  • Whether the aging maintenance status (231 days since last release) affects stability or compatibility with recent Python patch versions.
  • Performance characteristics when formatting very large JSON files or deeply nested structures.
  • Real-world adoption and whether the deprecation notice has driven users away to fractured-json.

Package facts

License MIT (permissive)
Python support supports the current Python release (<4.0,>=3.9)
Install friction low — pure-Python wheel
Runtime dependencies 3 — wcwidth, setuptools, importlib-resources
Maintenance aging — 231 days since the last release
Last repo commit
First released
Downloads 1,069,547/month — #4,407 on PyPI (30-day window, as of 2026-08-14)
Known vulnerabilities none known (OSV.dev, checked 2026-08-14)

Evidence: compact_json-1.8.2-py3-none-any.whl

License :: OSI Approved :: MIT LicenseOperating System :: OS IndependentProgramming Language :: Python :: 3Programming Language :: Python :: 3.10Programming Language :: Python :: 3.11Programming Language :: Python :: 3.12Programming Language :: Python :: 3.13Programming Language :: Python :: 3.14Programming Language :: Python :: 3.9

Tags

json formatter compacthuman readable json outputconfigurable json formattingjson line length controlpretty print json compact
json-formattingcli-tool

More Utilities packages