JSON formatting and validating tool
Project description
JSONator
Description
This module provides a command-line interface for formatting JSON files. It takes a path to either a JSON file or a directory containing JSON files as input and can recursively scan subdirectories for JSON files. The module returns an exit code indicating whether any files were reformatted or if there were any errors.
Usage
The main() function is the entry point for the module and returns an exit code indicating the result of the JSON formatting operation. The following arguments can be passed to the main() function:
-
path: A required argument that specifies the path to the JSON file or directory containing JSON files to be formatted.
-
--recursive or -r: An optional flag that specifies whether to scan subdirectories for JSON files.
-
--check: An optional flag that indicates whether to perform a dry run and return the status without actually reformatting the files. The exit code will indicate whether any files would be reformatted or if there were any errors.
-
--diff: Don't write the files back, just output a diff for each file on stdout.
-
--color: Show colored diff. Only applies when
--diff
is given. -
--sort-keys: Sort the output of dictionaries alphabetically by key. Available on Python 3.5+.
-
--no-ensure-ascii: Disable escaping of non-ASCII characters. Available on Python 3.9+.
-
--indent: Separate items with newlines and use this number of spaces for indentation.
-
--tab: Separate items with newlines and use tabs for indentation.
-
--no-indent: Separate items with spaces rather than newlines.
-
--compact: Suppress all whitespace separation (most compact).
--indent, --tab, --no-indent, --compact — mutually exclusive options for whitespace control. Available on Python 3.9+.
The module uses the ReturnCode enum to indicate the exit code of the formatting operation. The possible exit codes are:
-
0
: Indicates that no files would be reformatted. -
1
: Indicates that some files would be reformatted. -
122
: Indicates that the specified file or directory was not found. -
123
: Indicates that there was an internal error.
Example usage:
$ jsonator /path/to/json/file.json --check
Dev:
Build package
$ python -m build
Check package
$ twine check dist/*
Publish package
$ twine upload dist/*
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
Hashes for jsonator-0.1.11-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | cda7ca3741e02654f6d5eebc4c3410fe91858e39debccfa7c8da7b3284e167e7 |
|
MD5 | 5ec30659c8868da0c9746fed95f42879 |
|
BLAKE2b-256 | 8b2c9030089ae043ea668334d998fb9aeb0636c0da6fea8bb081f753ab584de0 |