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-jsondiffers frompretty-format-json? - 2. Why a separate project from
pretty-format-json? - 3. Usage
- 4. Instructions for Maintainers
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.devto install developer dependencies. - Run
pytestto execute the automated tests replicated from the upstream project. - Use
toxto exercise the full test matrix, linting, and formatting targets.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file format_json-0.1.1.tar.gz.
File metadata
- Download URL: format_json-0.1.1.tar.gz
- Upload date:
- Size: 9.3 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
ba7884e599bfa3da7266c372919572ef464e4af8eae807a8d4181158744d0733
|
|
| MD5 |
a3a59df0049c1d509ca1d6059bfc9ff2
|
|
| BLAKE2b-256 |
b8348d40350249a85eb701858b46dd9ea6cf000c91e4d08eca1705c8e4af19a7
|
File details
Details for the file format_json-0.1.1-py3-none-any.whl.
File metadata
- Download URL: format_json-0.1.1-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
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
7500ca53ec51a6be41df380042a12e4895c6d8081e8a63f6c54e3a72bbaa8e38
|
|
| MD5 |
69341249a4e73509082ce4ea2f7ec31e
|
|
| BLAKE2b-256 |
4f3485d8633ace16b409f35c371d50bd7fec150b342b6124e30bec02d4c0c42f
|