Lints, formats, and diffs JSON files
Project description
json-lint-tools
Provides linting, diffing and formatting JSON. Diffing and linting is done by comparing an input (file or stdin) to what would be produced by
loading the string with json.load(data)
then dumping it again with json.dumps(data)
with options to order keys, order items in arrays, and
specify the expected indentation. The CLI tool can optionally update the original file with the pretty formatted JSON output.
This package is primarily intended as a CLI tool for linting and formatting JSON. Thereis however documentation for the API HERE
Installation
pip install json-lint-tools
CLI Usage
usage: jsonfmt [-h] [--check] [-d] [-f] [-i INDENT] [--no-color] [-r] [-s] [--sort-arrays] [--sort-keys] [--stdin] [path ...]
positional arguments:
path Path to a single file or directory of JSON files
options:
-h, --help show this help message and exit
--check Only check if the files would be changed. Show a list of any files that would be changed and exit with an error if any would be
-d, --diff Show a diff
-f, --format Format non-conforming files
-i INDENT, --indent INDENT
How many spaces are expected per indentation
--no-color Don't print colors to stdout
-r, --recursive Search recursively for JSON files
-s, --sort Sort all objects by key and all arrays alphabetically. Shorthand for --sort-keys + --sort-arrays
--sort-arrays Sort arrays alphabetically
--sort-keys Sort keys in JSON objects alphabetically
--stdin Read data from stdin instead of a file
Examples
Getting a pretty diff:
> jsonfmt -r -d tests/jsonfiles File: tests/jsonfiles/test.json
---
+++
@@ -6,9 +6,9 @@
],
"baz": {
"myarry": [
- "b",
- "d",
- "a"
+ "b",
+ "d",
+ "a"
]
}
}
File: tests/jsonfiles/root_array.json
---
+++
@@ -1 +1,8 @@
-["a", "d", "b", {"foo": "bar"}]
+[
+ "a",
+ "d",
+ "b",
+ {
+ "foo": "bar"
+ }
+]
File: tests/jsonfiles/one_line_obj.json
---
+++
@@ -1 +1,4 @@
-{"foo": "bar", "bar": "baz"}
+{
+ "foo": "bar",
+ "bar": "baz"
+}
Formatting stdin:
> echo '{"foo": "bar"}' | jsonfmt
{
"foo": "bar"
}
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
json_lint_tools-0.1.2.tar.gz
(4.9 kB
view details)
Built Distribution
File details
Details for the file json_lint_tools-0.1.2.tar.gz
.
File metadata
- Download URL: json_lint_tools-0.1.2.tar.gz
- Upload date:
- Size: 4.9 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/1.7.1 CPython/3.11.0 Linux/6.2.0-1018-azure
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 74be18623497a6aef17fc108feb740a5ceabe84191bf489c6dd3733291f5920d |
|
MD5 | 464d255454d144e69a7aa79f044d6238 |
|
BLAKE2b-256 | 091831e80c46d1fdf632a181725c5fe96850a22124dc21c0b3c1670395e6b321 |
File details
Details for the file json_lint_tools-0.1.2-py3-none-any.whl
.
File metadata
- Download URL: json_lint_tools-0.1.2-py3-none-any.whl
- Upload date:
- Size: 6.0 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/1.7.1 CPython/3.11.0 Linux/6.2.0-1018-azure
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 846d7900dea0e2fcab4554c811da8b27457b0694e0d176c400af7c8c80981504 |
|
MD5 | 4bbf3702c45cbf59004591a75380a029 |
|
BLAKE2b-256 | 23dffec729fae16a4205eeb0196a8b1b4931faa6396c3c05ef987d75a6bd7afc |