Skip to main content

JSON formatting and validating tool

Project description

JSONator

License Downloads

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


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

jsonator-0.1.11.tar.gz (6.5 kB view hashes)

Uploaded Source

Built Distribution

jsonator-0.1.11-py3-none-any.whl (8.2 kB view hashes)

Uploaded Python 3

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page