https://github.com/mrvi0/cli-json-formatter
Lightweight CLI tool for JSON validation and formatting. Fast bash script with jq dependency
https://github.com/mrvi0/cli-json-formatter
bash cli cli-utility command-line-tool formatter json json-prettifier linux shell-script utility validator
Last synced: 28 days ago
JSON representation
Lightweight CLI tool for JSON validation and formatting. Fast bash script with jq dependency
- Host: GitHub
- URL: https://github.com/mrvi0/cli-json-formatter
- Owner: mrvi0
- License: mit
- Created: 2025-07-02T15:23:35.000Z (11 months ago)
- Default Branch: main
- Last Pushed: 2025-07-02T15:53:47.000Z (11 months ago)
- Last Synced: 2025-07-02T16:45:27.978Z (11 months ago)
- Topics: bash, cli, cli-utility, command-line-tool, formatter, json, json-prettifier, linux, shell-script, utility, validator
- Language: Shell
- Homepage:
- Size: 0 Bytes
- Stars: 0
- Watchers: 0
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# JSON Formatter & Validator CLI
[](https://opensource.org/licenses/MIT)
[](https://www.gnu.org/software/bash/)
[](https://stedolan.github.io/jq/)
[](https://www.linux.org/)
[](https://github.com/mrvi0/cli-json-fomatter)
๐ Lightweight and fast CLI tool for JSON validation and formatting.
## โจ Features
- โ
**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
## ๐ ๏ธ Installation
[](https://github.com/mrvi0/cli-json-fomatter)
[](https://www.linux.org/)
[](https://stedolan.github.io/jq/)
### Quick Installation (Recommended)
```bash
# Clone the repository
git clone https://github.com/mrvi0/cli-json-fomatter.git
cd json-formatter-cli
# Install to system
sudo ./install.sh
```
### Manual Installation
```bash
# 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/
```
## ๐ Usage
[](https://github.com/mrvi0/cli-json-fomatter)
[](https://github.com/mrvi0/cli-json-fomatter)
[](https://github.com/mrvi0/cli-json-fomatter)
### Basic Usage
```bash
# 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
```
### Command Line Options
```bash
# 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
```
### Usage Examples
#### 1. Validate JSON File
```bash
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",
...
}
```
#### 2. Format with Information
```bash
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
```
#### 3. Save to File
```bash
jsonfmt -f examples/sample.json -o formatted.json
```
**Output:**
```
โ
JSON is valid (file: examples/sample.json)
๐ Formatted JSON saved to: formatted.json
```
#### 4. Error Handling
```bash
jsonfmt -f invalid.json
```
**Output:**
```
โ Invalid JSON (file: invalid.json):
parse error: Unexpected token } at line 1, column 15
```
## ๐งช Testing
[](https://github.com/mrvi0/cli-json-fomatter)
[](https://github.com/mrvi0/cli-json-fomatter)
[](https://github.com/mrvi0/cli-json-fomatter)
Run tests to verify functionality:
```bash
chmod +x test.sh
./test.sh
```
Tests verify:
- Valid JSON validation
- Invalid JSON handling
- JSON string formatting
- File saving
- Indentation settings
- Help output
## ๐ Project Structure
```
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
```
## ๐ง Technical Details
### Dependencies
- **jq** - JSON processor for validation and formatting
- **bash 4.0+** - command line interpreter
### Main Functions
- `validate_json()` - JSON syntax validation
- `format_json()` - indentation formatting
- `read_file()` - safe file reading
- `write_file()` - safe file writing
- `get_json_info()` - JSON metadata extraction
### Error Handling
- JSON syntax validation via jq
- File existence and permission checks
- Read/write error handling
- Clear error messages with colored output
## ๐ฏ Bash Version Advantages
[](https://github.com/mrvi0/cli-json-fomatter)
[](https://stedolan.github.io/jq/)
[](https://github.com/mrvi0/cli-json-fomatter)
[](https://www.linux.org/)
- โก **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
## ๐ฏ Project Usage
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
## ๐ค Contributing
1. Fork the repository
2. Create a feature branch (`git checkout -b feature/amazing-feature`)
3. Commit your changes (`git commit -m 'Add amazing feature'`)
4. Push to the branch (`git push origin feature/amazing-feature`)
5. Open a Pull Request
## ๐ License
This project is licensed under the MIT License. See the `LICENSE` file for details.
## ๐จโ๐ป Author
**Vi** - [GitHub](https://github.com/mrvi0)
### ๐ Support
- **Telegram:** [t.me/b4dcat](https://t.me/b4dcat)
- **Email:** support@b4dcat.ru
---
โญ If you like this project, give it a star on GitHub!