compact-json
A JSON formatter that produces compact but human-readable
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-jsonuv
uv add compact-jsonpoetry
poetry add compact-jsonInstalling 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
Tags
More Utilities packages
Converts domain names between Unicode and…
permissive · top 100 on PyPI
charset-normalizerDetects and normalizes text encoding from…
permissive · top 100 on PyPI
setuptoolsSetuptools is a Python build backend and…
permissive · top 100 on PyPI
pluggyPluggy provides a plugin system that lets you…
permissive · top 100 on PyPI
PygmentsPygments is a syntax highlighter that colorizes…
permissive · top 100 on PyPI
sixSix provides utility functions to write Python…
permissive · top 100 on PyPI
condense-jsonCondense JSON by replacing repeated strings and…
permissive · top 15,000 on PyPI
xmlformatterFormats and compresses XML documents by…
permissive · top 15,000 on PyPI
dmiparserParses dmidecode output into structured Python…
permissive · top 15,000 on PyPI
objprintobjprint provides functions to print Python…
permissive · top 5,000 on PyPI
perkyPerky parses a minimal, human-friendly text…
permissive · top 15,000 on PyPI
jsonstreamsWrites JSON documents in a streaming format…
permissive · top 15,000 on PyPI
risonEncodes and decodes data to and from Rison, a…
permissive · top 15,000 on PyPI
json-flattenConverts nested JSON objects into flat…
permissive · top 15,000 on PyPI
jsondiffComputes structured diffs between JSON and…
permissive · top 5,000 on PyPI