Skip to content

SpdrByte/validate-json

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

3 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

JSON Validator Utility

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.

🚀 Key Features

  • 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 .json files.
  • 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.

🛠 Installation

1. Clone the repository

git clone https://github.com/SpdrByte/json-validator.git
cd json-validator

2. Install Dependencies

This utility requires Python 3.6+ and the chardet library for advanced encoding detection.

pip install -r requirements.txt

📖 Usage

The utility is designed to be flexible. Below are the most common use cases:

Case 1: Quick Scan (Current Directory)

Run the validator in your current folder to check all JSON files.

python validate_json.py

Case 2: Scan a Specific Directory

Pass the path to a specific folder to limit the scope of the scan.

python validate_json.py ./data/configs

Case 3: Detailed Encoding Information (Verbose)

If you are dealing with legacy files and want to see exactly which encoding was detected for each file:

python validate_json.py . --verbose

Case 4: CI/CD Pipeline (Fail-Fast)

In an automated environment, you often want to stop as soon as the first error is found to save time.

python validate_json.py . --fail-fast

Case 5: Integrating into Scripts

The 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..."

📋 Requirements

  • Python: 3.6 or higher
  • chardet: (Optional but recommended) For detecting non-UTF-8 file encodings.

🤝 Contributing

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

  1. Fork the Project
  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

Distributed under the MIT License. See LICENSE for more information.

About

Recursively validating JSON files - handles complex character encodings (UTF-8, UTF-16, etc.)

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages