A robust, lightweight Python utility for recursively validating JSON files. Unlike standard linters, this tool handles complex character encodings (UTF-8, UTF-16, etc.) and is optimized for both manual use and CI/CD pipelines.
- Fast-Path Validation: Attempts standard UTF-8 parsing first for maximum performance.
- Encoding Detection: Automatically detects and handles non-UTF-8 encodings using
chardet. - Recursive Scanning: Deep-searches directories for all
.jsonfiles. - CI/CD Ready: Returns proper exit codes (0 for success, 1 for failure) and supports "fail-fast" modes.
- Memory Efficient: Optimized for large JSON files by using chunked encoding detection.
git clone https://github.com/SpdrByte/json-validator.git
cd json-validatorThis utility requires Python 3.6+ and the chardet library for advanced encoding detection.
pip install -r requirements.txtThe utility is designed to be flexible. Below are the most common use cases:
Run the validator in your current folder to check all JSON files.
python validate_json.pyPass the path to a specific folder to limit the scope of the scan.
python validate_json.py ./data/configsIf you are dealing with legacy files and want to see exactly which encoding was detected for each file:
python validate_json.py . --verboseIn an automated environment, you often want to stop as soon as the first error is found to save time.
python validate_json.py . --fail-fastThe utility exits with 1 if any file fails validation and 0 if all pass, making it easy to chain with other commands:
python validate_json.py . && echo "All files are valid! Deploying..."- Python: 3.6 or higher
- chardet: (Optional but recommended) For detecting non-UTF-8 file encodings.
Contributions are welcome! Please feel free to submit a Pull Request.
- Fork the Project
- Create your Feature Branch (
git checkout -b feature/AmazingFeature) - Commit your Changes (
git commit -m 'Add some AmazingFeature') - Push to the Branch (
git push origin feature/AmazingFeature) - Open a Pull Request
Distributed under the MIT License. See LICENSE for more information.