Skip to main content

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"
}

Metadata

Release files for json-lint-tools 0.1.2

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for json-lint-tools 0.1.2
File Size Uploaded
json_lint_tools-0.1.2.tar.gz 4.9 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for json-lint-tools 0.1.2
File Interpreter ABI Platform
json_lint_tools-0.1.2-py3-none-any.whl Python 3 none any Details

Total release size: 11.0 kB

Release files / json_lint_tools-0.1.2.tar.gz

Download URL json_lint_tools-0.1.2.tar.gz
Size 4.9 kB
Tags Source
SHA-256 checksum
How to use checksums
74be18623497a6aef17fc108feb740a5ceabe84191bf489c6dd3733291f5920d
BLAKE2b-256 checksum
How to use checksums
091831e80c46d1fdf632a181725c5fe96850a22124dc21c0b3c1670395e6b321
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via poetry/1.7.1 CPython/3.11.0 Linux/6.2.0-1018-azure

Release files / json_lint_tools-0.1.2-py3-none-any.whl

Download URL json_lint_tools-0.1.2-py3-none-any.whl
Size 6.0 kB
Tags Python 3
SHA-256 checksum
How to use checksums
846d7900dea0e2fcab4554c811da8b27457b0694e0d176c400af7c8c80981504
BLAKE2b-256 checksum
How to use checksums
23dffec729fae16a4205eeb0196a8b1b4931faa6396c3c05ef987d75a6bd7afc
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via poetry/1.7.1 CPython/3.11.0 Linux/6.2.0-1018-azure

Release history Release notifications | RSS feed

This release

0.1.2 This release

2 release files

0.1.1

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page