Skip to main content

A tool for formatting JSON files

Project description

JFormat

A command-line tool for formatting and prettifying JSON files with customizable sorting options.

Quick Start

# Install the package
pip install jformat

# Format a JSON file
echo '{"b":1,"a":2}' > input.json
jformat input.json

Features

  • Pretty print JSON with proper indentation
  • Optional sorting of JSON keys
  • Simple command-line interface
  • Support for large JSON files
  • Preserves JSON data types

Installation

You can install JFormat using pip:

pip install jformat

For development installation:

git clone https://github.com/hwang2006/jformat.git
cd jformat
pip install -e .

Usage

Basic usage:

# Format with default settings (sorted keys)
jformat input.json

# Format without sorting keys
jformat --no-sort input.json

Options

  • --sort / --no-sort: Enable or disable sorting of JSON keys (default: --sort)
  • FILE_PATH: Path to the JSON file to format

Examples

  1. Format a JSON file with sorted keys:
jformat examples/input.json

Input:

{"b": 1,"a": 2,"c": {"z": 3,"y": 4}}

Output:

{
    "a": 2,
    "b": 1,
    "c": {
        "y": 4,
        "z": 3
    }
}
  1. Format without sorting keys (preserves original order):
jformat --no-sort examples/input.json

Development

Setup Development Environment

# Clone the repository
git clone https://github.com/hwang2006/jformat.git
cd jformat

# Create and activate virtual environment (optional)
python -m venv venv
source venv/bin/activate  # On Windows: venv\Scripts\activate

# Install only the core/basic requirements, when you just want to work with the package functionality
pip install -e .

# Install development dependencies, when you plan to develop, test, or contribute to the package
pip install -e ".[dev]"

Running Tests

pytest tests/

Project Structure

jformat/
├── setup.py           # Package configuration and metadata
├── README.md         # Project documentation
├── LICENSE           # MIT License details
├── MANIFEST.in       # Package inclusion rules
├── CHANGELOG.md      # Version history and changes
├── requirements.txt  # Core package dependencies
├── requirements-dev.txt  # Development dependencies
├── examples/         # Example JSON files for testing
│   ├── input.json    # Basic JSON example
│   └── example.json  # Complex JSON example
├── tests/            # Test suite directory
│   ├── __init__.py   # Makes tests a package
│   └── test_formatter.py  # Unit tests for formatter
└── jformat/          # Main package source
    ├── __init__.py   # Package initialization
    └── cli.py        # Command line interface implementation

Contributing

Contributions are welcome! Please feel free to submit a Pull Request.

  1. Fork the repository
  2. Create your feature branch (git checkout -b feature/AmazingFeature)
  3. Commit your changes (git commit -m 'Add some AmazingFeature')
  4. Push to the branch (git push origin feature/AmazingFeature)
  5. Open a Pull Request

License

This project is licensed under the MIT License - see the LICENSE file for details.

Author

Soonwook Hwang - hwang@kisti.re.kr

Acknowledgments

  • Inspired by Python's built-in json.tool
  • Built with Click

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

jformat-0.0.4.tar.gz (7.4 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

jformat-0.0.4-py3-none-any.whl (7.1 kB view details)

Uploaded Python 3

File details

Details for the file jformat-0.0.4.tar.gz.

File metadata

  • Download URL: jformat-0.0.4.tar.gz
  • Upload date:
  • Size: 7.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.0.1 CPython/3.11.11

File hashes

Hashes for jformat-0.0.4.tar.gz
Algorithm Hash digest
SHA256 48403c07e655b2f50cdd2b5a7362172bd234c39c345d50c8b18c4dcd153df0fd
MD5 e9beee36db62990d0477acd9f923e5c7
BLAKE2b-256 d1268068bc336dec53d98e806e0a6da143dff5eadda483e3beb96d52340e25e5

See more details on using hashes here.

File details

Details for the file jformat-0.0.4-py3-none-any.whl.

File metadata

  • Download URL: jformat-0.0.4-py3-none-any.whl
  • Upload date:
  • Size: 7.1 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.0.1 CPython/3.11.11

File hashes

Hashes for jformat-0.0.4-py3-none-any.whl
Algorithm Hash digest
SHA256 f67c2c48a595f8001c1fd5ca5bfbc16855d7841bffaf3a031d9ef84be5ed20b4
MD5 0a9051b109a58535e51a91887c7518d3
BLAKE2b-256 69190f190bd48825d294a16f4bdb83d042d2488977e5bd0a38365fffee86f431

See more details on using hashes here.

Supported by

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