Skip to main content

format-json

format-json is a JSON formatter that ships both a standalone CLI and a pre-commit hook. It is adapted from the pretty-format-json pre-commit hook, with only one difference, as seen below.

Table of Contents:

1. format-json vs pretty-format-json

Feature format-json pretty-format-json
Config option for trailing newline ✅ ❌ (Won't implement ever)
Preserves all digits of floats ✅ ❌ (Unresolved since 2022)

2. Usage

2.1. As a command-line tool

First, install it:

pip install format-json

Then, in the terminal, you can do something like:

format-json --autofix --no-eof-newline path/to/file.json

All command-line options from pretty-format-json are preserved, with the new --no-eof-newline flag layered on top. See Section 2.3 for the complete set of config options.

2.2. As a pre-commit hook

Add the hook to your .pre-commit-config.yaml:

- repo: https://github.com/jsh9/format-json
  rev: <LATEST_VERSION>
  hooks:
    - id: format-json
      args: [--autofix, --no-eof-newline]

(You can choose your own args.)

2.3. Configuration options

format-json accepts the same options whether invoked via the CLI or pre-commit. Combine them as needed for your workflow:

  • --autofix - automatically format json files
  • --indent ... - Control the indentation (either a number for a number of spaces or a string of whitespace). Defaults to 2 spaces.
  • --no-ensure-ascii preserve unicode characters instead of converting to escape sequences
  • --no-sort-keys - when autofixing, retain the original key ordering (instead of sorting the keys)
  • --top-keys comma,separated,keys - Keys to keep at the top of mappings.
  • --no-eof-newline: omit the trailing newline (format-json only).

3. Instructions for Maintainers

  • Run pip install -e . to install this project in the "editable" mode.
  • Run pip install -r requirements.dev to install developer dependencies.
  • Run pytest to execute the automated tests replicated from the upstream project.
  • Use tox to exercise the full test matrix, linting, and formatting targets.

Metadata

Release files for format-json 0.1.2

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for format-json 0.1.2
File Size Uploaded Provenance Actions
format_json-0.1.2.tar.gz 11.4 kB Without provenance Details for format_json-0.1.2.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for format-json 0.1.2
File Interpreter ABI Platform Actions
format_json-0.1.2-py3-none-any.whl Python 3 none any Details for format_json-0.1.2-py3-none-any.whl

Total release size: 18.7 kB

Release files / format_json-0.1.2.tar.gz

Download URL format_json-0.1.2.tar.gz
Size 11.4 kB
Tags Source
SHA-256 checksum
How to use checksums
65de970bf8ea55886cdcb5cbb95c308823365e408db6597439543f97e08d4251
BLAKE2b-256 checksum
How to use checksums
beccb7c951eddf2d3ad491cc8fc10c3bc8d010bd28b3cb74aab7206637d45f10
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.1.0 CPython/3.13.7

Release files / format_json-0.1.2-py3-none-any.whl

Download URL format_json-0.1.2-py3-none-any.whl
Size 7.2 kB
Tags Python 3
SHA-256 checksum
How to use checksums
aaa9971bde0e9d9131cdbdc073017526d7f5a87b2131b42cd408850b68e15a75
BLAKE2b-256 checksum
How to use checksums
0ccafe397032531f633bc998f841ab6ca2d87a009b93a1ff8338ba3c0054be4f
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.1.0 CPython/3.13.7

Security for format-json 0.1.2

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page