π Lightweight and fast CLI tool for JSON validation and formatting.
- β JSON Validation - check JSON syntax correctness
- π¨ Pretty Print - beautiful formatting with customizable indentation
- π File Operations - read from files and save results
- π§ Flexible Options - customize indentation, show additional information
- π― Error Handling - clear error messages
- π JSON Information - statistics and metadata
- β‘ Fast Startup - single bash script, no npm dependencies
# Clone the repository
git clone https://github.com/mrvi0/cli-json-fomatter.git
cd json-formatter-cli
# Install to system
sudo ./install.sh
# Install jq (if not installed)
sudo apt install jq # Ubuntu/Debian
sudo yum install jq # CentOS/RHEL
sudo pacman -S jq # Arch Linux
# Make script executable
chmod +x jsonfmt
# Copy to system directory
sudo cp jsonfmt /usr/local/bin/
# Validate and format JSON string
jsonfmt '{"name": "John", "age": 30}'
# Work with file
jsonfmt -f examples/sample.json
# Read from stdin
echo '{"data": "value"}' | jsonfmt
# Save result to file
jsonfmt -f input.json -o output.json
# Customize indentation (default: 2 spaces)
jsonfmt -f input.json -i 4
# Show additional information
jsonfmt -f input.json --info
# Full help
jsonfmt --help
jsonfmt -f examples/sample.json
Output:
β
JSON is valid (file: examples/sample.json)
π Formatted JSON:
{
"name": "JSON Formatter CLI",
"version": "1.0.0",
"description": "A command-line tool for JSON validation and formatting",
...
}
jsonfmt -f examples/sample.json --info
Output:
β
JSON is valid (file: examples/sample.json)
π Formatted JSON:
{...}
π JSON Information:
Root element type: Object
Size: 456 characters
Number of properties: 6
jsonfmt -f examples/sample.json -o formatted.json
Output:
β
JSON is valid (file: examples/sample.json)
π Formatted JSON saved to: formatted.json
jsonfmt -f invalid.json
Output:
β Invalid JSON (file: invalid.json):
parse error: Unexpected token } at line 1, column 15
Run tests to verify functionality:
chmod +x test.sh
./test.sh
Tests verify:
- Valid JSON validation
- Invalid JSON handling
- JSON string formatting
- File saving
- Indentation settings
- Help output
json-formatter-cli/
βββ jsonfmt # Main bash script
βββ install.sh # Installation script
βββ uninstall.sh # Uninstall script
βββ test.sh # Tests
βββ examples/
β βββ sample.json # Sample JSON file
βββ README.md # Documentation
βββ LICENSE # MIT license
βββ .gitignore # Ignored files
- jq - JSON processor for validation and formatting
- bash 4.0+ - command line interpreter
validate_json()
- JSON syntax validationformat_json()
- indentation formattingread_file()
- safe file readingwrite_file()
- safe file writingget_json_info()
- JSON metadata extraction
- JSON syntax validation via jq
- File existence and permission checks
- Read/write error handling
- Clear error messages with colored output
- β‘ Fast Startup - no npm install required
- π― Minimal Dependencies - only jq
- π§ Simple Installation - single installation script
- π¦ Lightweight - single file ~5KB
- π§ Native Linux Support - works out of the box
- π¨ Colored Output - beautiful result display
This CLI tool is perfect for:
- Validating JSON configuration files
- Formatting API responses
- Data validation in CI/CD pipelines
- JSON processing in automation scripts
- Quick JSON checking in command line
- Fork the repository
- Create a feature branch (
git checkout -b feature/amazing-feature
) - Commit your changes (
git commit -m 'Add amazing feature'
) - Push to the branch (
git push origin feature/amazing-feature
) - Open a Pull Request
This project is licensed under the MIT License. See the LICENSE
file for details.
Vi - GitHub
- Telegram: t.me/b4dcat
- Email: support@b4dcat.ru
β If you like this project, give it a star on GitHub!