Metadata-Version: 2.4
Name: format-json
Version: 0.1.2
Summary: A CLI and pre-commit hook for formatting JSON with configurable trailing newline handling.
Project-URL: Homepage, https://github.com/jsh9/format-json
Project-URL: Repository, https://github.com/jsh9/format-json
Project-URL: Issues, https://github.com/jsh9/format-json/issues
Author: format-json maintainers
License: MIT License
        
        Copyright (c) 2025 jsh9
        
        Permission is hereby granted, free of charge, to any person obtaining a copy
        of this software and associated documentation files (the "Software"), to deal
        in the Software without restriction, including without limitation the rights
        to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
        copies of the Software, and to permit persons to whom the Software is
        furnished to do so, subject to the following conditions:
        
        The above copyright notice and this permission notice shall be included in all
        copies or substantial portions of the Software.
        
        THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
        IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
        FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
        AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
        LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
        OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
        SOFTWARE.
        
        ----
        
        The majority of this project's data files and code files are copied/adopted
        from https://github.com/pre-commit/pre-commit-hooks. Below is the original
        license of pre-commit-hooks.
        
        ----
        
        Copyright (c) 2014 pre-commit dev team: Anthony Sottile, Ken Struys
        
        Permission is hereby granted, free of charge, to any person obtaining a copy
        of this software and associated documentation files (the "Software"), to deal
        in the Software without restriction, including without limitation the rights
        to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
        copies of the Software, and to permit persons to whom the Software is
        furnished to do so, subject to the following conditions:
        
        The above copyright notice and this permission notice shall be included in
        all copies or substantial portions of the Software.
        
        THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
        IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
        FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
        AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
        LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
        OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
        THE SOFTWARE.
License-File: LICENSE
Keywords: cli,formatter,json,pre-commit
Classifier: License :: OSI Approved :: MIT License
Classifier: Programming Language :: Python :: 3
Classifier: Programming Language :: Python :: 3 :: Only
Classifier: Programming Language :: Python :: 3.10
Classifier: Programming Language :: Python :: 3.11
Classifier: Programming Language :: Python :: 3.12
Classifier: Programming Language :: Python :: 3.13
Classifier: Topic :: Software Development :: Build Tools
Classifier: Topic :: Utilities
Requires-Python: >=3.10
Provides-Extra: dev
Requires-Dist: flake8-broken-line; extra == 'dev'
Requires-Dist: flake8-clean-block; extra == 'dev'
Requires-Dist: flake8-picky-parentheses; extra == 'dev'
Requires-Dist: muff; extra == 'dev'
Requires-Dist: mypy; extra == 'dev'
Requires-Dist: pre-commit; extra == 'dev'
Requires-Dist: pytest; extra == 'dev'
Description-Content-Type: text/markdown

# 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`](https://github.com/pre-commit/pre-commit-hooks)
pre-commit hook, with only one difference, as seen below.

**Table of Contents:**

<!--TOC-->

- [1. `format-json` vs `pretty-format-json`](#1-format-json-vs-pretty-format-json)
- [2. Usage](#2-usage)
  - [2.1. As a command-line tool](#21-as-a-command-line-tool)
  - [2.2. As a pre-commit hook](#22-as-a-pre-commit-hook)
  - [2.3. Configuration options](#23-configuration-options)
- [3. Instructions for Maintainers](#3-instructions-for-maintainers)

<!--TOC-->

## 1. `format-json` vs `pretty-format-json`

| Feature                            | format-json | pretty-format-json                                                                      |
| ---------------------------------- | :---------: | --------------------------------------------------------------------------------------- |
| Config option for trailing newline |     ✅      | ❌ ([Won't implement ever](https://github.com/pre-commit/pre-commit-hooks/issues/1203)) |
| Preserves all digits of floats     |     ✅      | ❌ ([Unresolved since 2022](https://github.com/pre-commit/pre-commit-hooks/issues/780)) |

## 2. Usage

### 2.1. As a command-line tool

First, install it:

```bash
pip install format-json
```

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

```bash
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](#23-configuration-options) for the complete set of config
options.

### 2.2. As a pre-commit hook

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

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