Name | json-indent JSON |
Version |
2.7.5
JSON |
| download |
home_page | None |
Summary | Simple Python-based JSON parser/indenter/formatter |
upload_time | 2024-11-17 02:33:21 |
maintainer | None |
docs_url | None |
author | None |
requires_python | >=3.10 |
license | MIT License Copyright (c) 2016-2024 Jim Knoble 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. |
keywords |
cli
indent
json
pre-commit
reformat
|
VCS |
|
bugtrack_url |
|
requirements |
No requirements were recorded.
|
Travis-CI |
No Travis.
|
coveralls test coverage |
No coveralls.
|
# json-indent
[![EditorConfig-enabled](https://img.shields.io/badge/EditorConfig-enabled-brightgreen?logo=EditorConfig&logoColor=white)](https://editorconfig.org/)
[![pre-commit-enabled](https://img.shields.io/badge/pre--commit-enabled-brightgreen?logo=pre-commit&logoColor=white)](https://github.com/pre-commit/pre-commit)
[![Python-3.7+](https://img.shields.io/badge/Python-3.7+-informational?logo=Python&logoColor=white)](https://www.python.org)
[![CodeStyle-ruff](https://img.shields.io/badge/CodeStyle-ruff-informational)](https://astral.sh/ruff)
[![pre-commit-hook-included](https://img.shields.io/badge/pre--commit--hook-included-brightgreen?logo=pre-commit&logoColor=white)](#pre-commit-hook)
This is a simple Python-based tool for parsing/indenting/formatting JSON.
Python's `json` module actually contains such a tool; it's even simpler and is
missing twiddles for specifying the amount of indent, whether to (re)compact,
and whether to sort keys when parsing.
**json-indent** can be useful:
- On the command-line
- From within [Vim][] or similar editors
- As a [pre-commit][] hook
([js-beautify][] is another such tool; it can parse JavaScript as well as
JSON, but it has no built-in [pre-commit][] hook).
[begintoc]: #
## Contents
- [Requirements](#requirements)
- [Installing](#installing)
- [How to Use](#how-to-use)
- [Quickstart](#quickstart)
- [Command-line Autocompletion](#command-line-autocompletion)
- [Advanced Topics](#advanced-topics)
- [Pre-Commit Hook](#pre-commit-hook)
- [Integration with Vim](#integration-with-vim)
- [Developing json-indent](#developing-json-indent)
- [References](#references)
[endtoc]: # (Generated by mark-toc pre-commit hook)
## Requirements
- A [Python] interpreter, version 3.7 or later (version 2.7 support is
deprecated, but may still work)
## Installing
It is recommended to install **json-indent** either:
- In its own virtual environment (for example, using [uv][]), or
- As a [pre-commit hook](#pre-commit-hook)
To install with `uv`:
uv tool install json-indent
## How to Use
For a summary of all the available options:
uv tool run json-indent --help
Or, with the `uvx` shortcut:
uvx json-indent --help
Or, if you prefer to call the script directly:
/path/to/json-indent --help
> [!TIP]
>
> There are a number of different ways to run tools that are delivered as
> Python modules. For the remainder of this document, we will use
> `uvx json-indent` to mean whichever one you prefer for your Python
> installation and operating environment.
>
> See [How to Run Your Python Scripts][run-python-scripts] for more details.
### Quickstart
To read JSON from a file, parse it, and write it to the standard output:
uvx json-indent input.json
To write to a file instead:
uvx json-indent -o output.json input.json
To read from the standard input, you can use `-` as the filename:
uvx json-indent -o - -
Or simply:
uvx json-indent
To modify a file in place:
uvx json-indent --inplace input.json
To display `json-indent`'s version:
uvx json-indent --version
See the command-line help for more options, including:
- Indent size
- "Compact" mode
- Key sorting
## Command-line Autocompletion
**json-indent** provides command-line [autocompletion][] for the [Bash][]
command-line shell and compatible shells, using the
[argcomplete][argcomplete-pypi] Python package.
For instructions on how to enable completion:
uvx json-indent --completion-help
## Advanced Topics
### Pre-Commit Hook
**json-indent** has support for the [pre-commit][] framework for running tools
before committing to your git project. The hook will:
1. Parse your JSON files and emit messages about any errors it encounters.
2. Format and indent your JSON files according to the `--indent`, `--compact`,
and `--sort-keys` options you supply (or their default values if you don't
supply one).
To add a hook for **json-indent** to your project, use the following YAML in
your project's [.pre-commit-config.yaml](examples/pre-commit-config.yaml):
```yaml
- repo: https://github.com/jmknoble/json-indent
rev: v2.7.5
hooks:
- id: json-indent
```
> [!NOTE]
>
> **HOW IT WORKS:**
>
> Under the hood this uses a [.pre-commit-hooks.yaml](.pre-commit-hooks.yaml)
> file in the root of the Git project to define the parameters of the
> pre-commit hook.
>
> Key info:
>
> - **json-indent** must accept multiple input files on the command line.
> - The `--inplace` option is needed in order to automatically indent JSON
> source files.
### Integration with Vim
You can use **json-indent** from within [Vim][] to format JSON directly in
your editing session.
To enable this functionality, you can add the following to your [vimrc][]
file:
```viml
""""""""""""""""""""""""""""""""""""""""
" JSON parsing/indenting
" https://github.com/jmknoble/json-indent
"
" Normal mode
"
" Compact JSON stanza starting at current character (uses '%' to move to matching brace)
nmap <Leader>jc :%!json-indent -c
nmap <Leader>JC <Leader>jc
"
" Parse/indent JSON stanza contained in current line
nmap <Leader>jp 0!$json-indent<CR>j
nmap <Leader>JP <Leader>jp
"
" Parse/indent JSON stanza contained in current line with sorted keys
nmap <Leader>js 0!$json-indent -s<CR>j
nmap <Leader>JS <Leader>js
"
" Visual mode
"
" Compact JSON stanza contained in current selection
vmap <Leader>jc !json-indent -c<CR>j
vmap <Leader>JC <Leader>jc
"
" Parse/indent JSON stanza contained in current selection
vmap <Leader>jp !json-indent
vmap <Leader>JP <Leader>jp
"
" Parse/indent JSON stanza contained in current selection with sorted keys
vmap <Leader>js !json-indent -s<CR>j
vmap <Leader>JS <Leader>js
""""""""""""""""""""""""""""""""""""""""
```
> [!TIP]
>
> This uses the `!`_command_ feature to run an external command as a
> [filter][].
>
> Use the Vim command `:help mapleader` (or see [mapleader][]) for an
> explanation of `<Leader>`.
## Developing json-indent
See [DEVELOPING](DEVELOPING.md).
## References
- [Python][]:
- [How to Run Your Python Scripts][run-python-scripts]
- argcomplete on [PyPI][argcomplete-pypi] and [GitHub][argcomplete-github]
- [pre-commit][]
- [Vim][]:
- [Intro to vimrc][vimrc]
- [Vim filters][filter]
- [Vim's Leader key][mapleader]
- [js-beautify][]
[Python]: https://www.python.org/
[run-python-scripts]: https://realpython.com/run-python-scripts/
[uv]: https://github.com/astral-sh/uv
[argcomplete-pypi]: https://pypi.org/project/argcomplete/
[argcomplete-github]: https://github.com/kislyuk/argcomplete
[autocompletion]: https://en.wikipedia.org/wiki/Autocomplete
[Bash]: https://en.wikipedia.org/wiki/Bash_(Unix_shell)
[pre-commit]: https://pre-commit.com/
[Vim]: http://www.vim.org/
[vimrc]: https://vimhelp.org/usr_05.txt.html#vimrc-intro
[filter]: https://vimhelp.org/change.txt.html#filter
[mapleader]: https://vimhelp.org/map.txt.html#mapleader
[js-beautify]: https://github.com/beautify-web/js-beautify
Raw data
{
"_id": null,
"home_page": null,
"name": "json-indent",
"maintainer": null,
"docs_url": null,
"requires_python": ">=3.10",
"maintainer_email": null,
"keywords": "cli, indent, json, pre-commit, reformat",
"author": null,
"author_email": "jmknoble <jmknoble@pobox.com>",
"download_url": "https://files.pythonhosted.org/packages/cf/23/7c172355cea1fe573f6ae7db881a9ad8510b64c650d8466c070064f2802c/json_indent-2.7.5.tar.gz",
"platform": null,
"description": "# json-indent\n\n[![EditorConfig-enabled](https://img.shields.io/badge/EditorConfig-enabled-brightgreen?logo=EditorConfig&logoColor=white)](https://editorconfig.org/)\n[![pre-commit-enabled](https://img.shields.io/badge/pre--commit-enabled-brightgreen?logo=pre-commit&logoColor=white)](https://github.com/pre-commit/pre-commit)\n[![Python-3.7+](https://img.shields.io/badge/Python-3.7+-informational?logo=Python&logoColor=white)](https://www.python.org)\n[![CodeStyle-ruff](https://img.shields.io/badge/CodeStyle-ruff-informational)](https://astral.sh/ruff)\n[![pre-commit-hook-included](https://img.shields.io/badge/pre--commit--hook-included-brightgreen?logo=pre-commit&logoColor=white)](#pre-commit-hook)\n\n\nThis is a simple Python-based tool for parsing/indenting/formatting JSON.\n\nPython's `json` module actually contains such a tool; it's even simpler and is\nmissing twiddles for specifying the amount of indent, whether to (re)compact,\nand whether to sort keys when parsing.\n\n**json-indent** can be useful:\n\n- On the command-line\n- From within [Vim][] or similar editors\n- As a [pre-commit][] hook\n\n([js-beautify][] is another such tool; it can parse JavaScript as well as\nJSON, but it has no built-in [pre-commit][] hook).\n\n\n[begintoc]: #\n\n## Contents\n\n- [Requirements](#requirements)\n- [Installing](#installing)\n- [How to Use](#how-to-use)\n - [Quickstart](#quickstart)\n- [Command-line Autocompletion](#command-line-autocompletion)\n- [Advanced Topics](#advanced-topics)\n - [Pre-Commit Hook](#pre-commit-hook)\n - [Integration with Vim](#integration-with-vim)\n- [Developing json-indent](#developing-json-indent)\n- [References](#references)\n\n[endtoc]: # (Generated by mark-toc pre-commit hook)\n\n\n## Requirements\n\n- A [Python] interpreter, version 3.7 or later (version 2.7 support is\n deprecated, but may still work)\n\n\n## Installing\n\nIt is recommended to install **json-indent** either:\n\n- In its own virtual environment (for example, using [uv][]), or\n- As a [pre-commit hook](#pre-commit-hook)\n\nTo install with `uv`:\n\n uv tool install json-indent\n\n\n## How to Use\n\nFor a summary of all the available options:\n\n uv tool run json-indent --help\n\nOr, with the `uvx` shortcut:\n\n uvx json-indent --help\n\nOr, if you prefer to call the script directly:\n\n /path/to/json-indent --help\n\n> [!TIP]\n>\n> There are a number of different ways to run tools that are delivered as\n> Python modules. For the remainder of this document, we will use\n> `uvx json-indent` to mean whichever one you prefer for your Python\n> installation and operating environment.\n>\n> See [How to Run Your Python Scripts][run-python-scripts] for more details.\n\n\n### Quickstart\n\nTo read JSON from a file, parse it, and write it to the standard output:\n\n uvx json-indent input.json\n\nTo write to a file instead:\n\n uvx json-indent -o output.json input.json\n\nTo read from the standard input, you can use `-` as the filename:\n\n uvx json-indent -o - -\n\nOr simply:\n\n uvx json-indent\n\nTo modify a file in place:\n\n uvx json-indent --inplace input.json\n\nTo display `json-indent`'s version:\n\n uvx json-indent --version\n\nSee the command-line help for more options, including:\n\n- Indent size\n- \"Compact\" mode\n- Key sorting\n\n\n## Command-line Autocompletion\n\n**json-indent** provides command-line [autocompletion][] for the [Bash][]\ncommand-line shell and compatible shells, using the\n[argcomplete][argcomplete-pypi] Python package.\n\nFor instructions on how to enable completion:\n\n uvx json-indent --completion-help\n\n\n## Advanced Topics\n\n### Pre-Commit Hook\n\n**json-indent** has support for the [pre-commit][] framework for running tools\nbefore committing to your git project. The hook will:\n\n1. Parse your JSON files and emit messages about any errors it encounters.\n2. Format and indent your JSON files according to the `--indent`, `--compact`,\n and `--sort-keys` options you supply (or their default values if you don't\n supply one).\n\nTo add a hook for **json-indent** to your project, use the following YAML in\nyour project's [.pre-commit-config.yaml](examples/pre-commit-config.yaml):\n\n```yaml\n - repo: https://github.com/jmknoble/json-indent\n rev: v2.7.5\n hooks:\n - id: json-indent\n```\n\n> [!NOTE]\n>\n> **HOW IT WORKS:**\n>\n> Under the hood this uses a [.pre-commit-hooks.yaml](.pre-commit-hooks.yaml)\n> file in the root of the Git project to define the parameters of the\n> pre-commit hook.\n>\n> Key info:\n>\n> - **json-indent** must accept multiple input files on the command line.\n> - The `--inplace` option is needed in order to automatically indent JSON\n> source files.\n\n\n### Integration with Vim\n\nYou can use **json-indent** from within [Vim][] to format JSON directly in\nyour editing session.\n\nTo enable this functionality, you can add the following to your [vimrc][]\nfile:\n\n```viml\n\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\n\" JSON parsing/indenting\n\" https://github.com/jmknoble/json-indent\n\"\n\" Normal mode\n\"\n\" Compact JSON stanza starting at current character (uses '%' to move to matching brace)\nnmap <Leader>jc :%!json-indent -c\nnmap <Leader>JC <Leader>jc\n\"\n\" Parse/indent JSON stanza contained in current line\nnmap <Leader>jp 0!$json-indent<CR>j\nnmap <Leader>JP <Leader>jp\n\"\n\" Parse/indent JSON stanza contained in current line with sorted keys\nnmap <Leader>js 0!$json-indent -s<CR>j\nnmap <Leader>JS <Leader>js\n\"\n\" Visual mode\n\"\n\" Compact JSON stanza contained in current selection\nvmap <Leader>jc !json-indent -c<CR>j\nvmap <Leader>JC <Leader>jc\n\"\n\" Parse/indent JSON stanza contained in current selection\nvmap <Leader>jp !json-indent\nvmap <Leader>JP <Leader>jp\n\"\n\" Parse/indent JSON stanza contained in current selection with sorted keys\nvmap <Leader>js !json-indent -s<CR>j\nvmap <Leader>JS <Leader>js\n\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\n```\n\n> [!TIP]\n>\n> This uses the `!`_command_ feature to run an external command as a\n> [filter][].\n>\n> Use the Vim command `:help mapleader` (or see [mapleader][]) for an\n> explanation of `<Leader>`.\n\n\n## Developing json-indent\n\nSee [DEVELOPING](DEVELOPING.md).\n\n\n## References\n\n- [Python][]:\n - [How to Run Your Python Scripts][run-python-scripts]\n - argcomplete on [PyPI][argcomplete-pypi] and [GitHub][argcomplete-github]\n- [pre-commit][]\n- [Vim][]:\n - [Intro to vimrc][vimrc]\n - [Vim filters][filter]\n - [Vim's Leader key][mapleader]\n- [js-beautify][]\n\n\n [Python]: https://www.python.org/\n [run-python-scripts]: https://realpython.com/run-python-scripts/\n [uv]: https://github.com/astral-sh/uv\n\n [argcomplete-pypi]: https://pypi.org/project/argcomplete/\n [argcomplete-github]: https://github.com/kislyuk/argcomplete\n [autocompletion]: https://en.wikipedia.org/wiki/Autocomplete\n [Bash]: https://en.wikipedia.org/wiki/Bash_(Unix_shell)\n\n [pre-commit]: https://pre-commit.com/\n\n [Vim]: http://www.vim.org/\n [vimrc]: https://vimhelp.org/usr_05.txt.html#vimrc-intro\n [filter]: https://vimhelp.org/change.txt.html#filter\n [mapleader]: https://vimhelp.org/map.txt.html#mapleader\n\n [js-beautify]: https://github.com/beautify-web/js-beautify\n",
"bugtrack_url": null,
"license": "MIT License Copyright (c) 2016-2024 Jim Knoble 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.",
"summary": "Simple Python-based JSON parser/indenter/formatter",
"version": "2.7.5",
"project_urls": {
"Repository": "https://github.com/jmknoble/json-indent"
},
"split_keywords": [
"cli",
" indent",
" json",
" pre-commit",
" reformat"
],
"urls": [
{
"comment_text": "",
"digests": {
"blake2b_256": "f66d1f25cd40278198bef1ee98d4793c16f0295e69193fcbc0e14fa551c22c60",
"md5": "fde9e6ae12dc92e9ffcbd86feda74380",
"sha256": "d772d12fe6c8aaa5fcba8ddcb2031648efd74bdea76476b930df0e808dc65918"
},
"downloads": -1,
"filename": "json_indent-2.7.5-py3-none-any.whl",
"has_sig": false,
"md5_digest": "fde9e6ae12dc92e9ffcbd86feda74380",
"packagetype": "bdist_wheel",
"python_version": "py3",
"requires_python": ">=3.10",
"size": 15189,
"upload_time": "2024-11-17T02:33:19",
"upload_time_iso_8601": "2024-11-17T02:33:19.812204Z",
"url": "https://files.pythonhosted.org/packages/f6/6d/1f25cd40278198bef1ee98d4793c16f0295e69193fcbc0e14fa551c22c60/json_indent-2.7.5-py3-none-any.whl",
"yanked": false,
"yanked_reason": null
},
{
"comment_text": "",
"digests": {
"blake2b_256": "cf237c172355cea1fe573f6ae7db881a9ad8510b64c650d8466c070064f2802c",
"md5": "9ae587961f1f2d63297eed8c430947e7",
"sha256": "1ba175d31cd6a185bf2263af575100682a1460017179be3c2f6f994059009d8d"
},
"downloads": -1,
"filename": "json_indent-2.7.5.tar.gz",
"has_sig": false,
"md5_digest": "9ae587961f1f2d63297eed8c430947e7",
"packagetype": "sdist",
"python_version": "source",
"requires_python": ">=3.10",
"size": 34284,
"upload_time": "2024-11-17T02:33:21",
"upload_time_iso_8601": "2024-11-17T02:33:21.674026Z",
"url": "https://files.pythonhosted.org/packages/cf/23/7c172355cea1fe573f6ae7db881a9ad8510b64c650d8466c070064f2802c/json_indent-2.7.5.tar.gz",
"yanked": false,
"yanked_reason": null
}
],
"upload_time": "2024-11-17 02:33:21",
"github": true,
"gitlab": false,
"bitbucket": false,
"codeberg": false,
"github_user": "jmknoble",
"github_project": "json-indent",
"travis_ci": false,
"coveralls": false,
"github_actions": true,
"lcname": "json-indent"
}