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

Your Name - 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.1.tar.gz (4.8 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.1-py3-none-any.whl (4.6 kB view details)

Uploaded Python 3

File details

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

File metadata

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

File hashes

Hashes for jformat-0.0.1.tar.gz
Algorithm Hash digest
SHA256 21b9abb39ffea79086da16a041b2f4f5f4aef4894c605542d7f324232df3b42a
MD5 39c91fd2439b06ed2cdb2a5079150912
BLAKE2b-256 c5e72c1bfae3e9234e9b13af6e554ce6fd94263f7d75947269c97ae69a502d3e

See more details on using hashes here.

File details

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

File metadata

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

File hashes

Hashes for jformat-0.0.1-py3-none-any.whl
Algorithm Hash digest
SHA256 a5c892f6adcb9af66ed57c69337b09d1b99d8493de5e2471a560b7b746a6b376
MD5 a93075194d036dd489abf0099af263c0
BLAKE2b-256 1aba732667b6e13c04c8b61947467caf0e01bc44b6ffaae3dc4972b41d2ebfd6

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