Skip to main content

A CLI and pre-commit hook for formatting JSON with configurable trailing newline handling.

Project description

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. How does format-json differs from pretty-format-json?

Feature format-json pretty-format-json
Config option for trailing newline

2. Why a separate project from pretty-format-json?

There are oftentimes practical reasons for JSON files to not have a trailing newline.

But the maintainers of pretty-format-json hard-coded a newline at the end of the formatted JSON, and they chose not to offer a configuration option for this.

3. Usage

3.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.

3.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.)

4. 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.

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

format_json-0.1.0.tar.gz (9.2 kB view details)

Uploaded Source

Built Distribution

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

format_json-0.1.0-py3-none-any.whl (6.3 kB view details)

Uploaded Python 3

File details

Details for the file format_json-0.1.0.tar.gz.

File metadata

  • Download URL: format_json-0.1.0.tar.gz
  • Upload date:
  • Size: 9.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for format_json-0.1.0.tar.gz
Algorithm Hash digest
SHA256 0f723ef5e8353bd6ce103281091e64a58564799422bbc4271f62c5fb9579a931
MD5 eacc339ccddc82add0a2e45e2835cfb3
BLAKE2b-256 4398df8e177cfa0c4cf2c38358b18683362556348eed84c4ebe8a2c5a19c9b1d

See more details on using hashes here.

File details

Details for the file format_json-0.1.0-py3-none-any.whl.

File metadata

  • Download URL: format_json-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 6.3 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for format_json-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 35d38a69cc17bfb084409e32d00e28de758b05ed05e9e11b77584ba511167177
MD5 2dbe4022e241c0446224bd0b1272dd43
BLAKE2b-256 48f3eee7e31eac878918f15965df80b0c3f375023b224e23a9d67e1752de8ae6

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