An open API service indexing awesome lists of open source software.

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

Awesome Lists containing this project

README

          

# JSON Formatter & Validator CLI

[![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT)
[![Shell: Bash](https://img.shields.io/badge/Shell-Bash-4EAA25.svg)](https://www.gnu.org/software/bash/)
[![Dependency: jq](https://img.shields.io/badge/Dependency-jq%201.6+-blue.svg)](https://stedolan.github.io/jq/)
[![Platform: Linux](https://img.shields.io/badge/Platform-Linux%20%7C%20Unix-lightgrey.svg)](https://www.linux.org/)
[![Version: 1.0.0](https://img.shields.io/badge/Version-1.0.0-green.svg)](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

[![Installation](https://img.shields.io/badge/Installation-30%20seconds-brightgreen.svg)](https://github.com/mrvi0/cli-json-fomatter)
[![Platform](https://img.shields.io/badge/Platform-Linux%20%7C%20Unix-blue.svg)](https://www.linux.org/)
[![Dependencies](https://img.shields.io/badge/Dependencies-Auto%20install-orange.svg)](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

[![Usage](https://img.shields.io/badge/Usage-Simple%20CLI-brightgreen.svg)](https://github.com/mrvi0/cli-json-fomatter)
[![Features](https://img.shields.io/badge/Features-Validation%20%7C%20Formatting-blue.svg)](https://github.com/mrvi0/cli-json-fomatter)
[![Output](https://img.shields.io/badge/Output-Colored%20%7C%20Pretty-orange.svg)](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

[![Tests](https://img.shields.io/badge/Tests-Automated%20Suite-brightgreen.svg)](https://github.com/mrvi0/cli-json-fomatter)
[![Coverage](https://img.shields.io/badge/Coverage-All%20Features-blue.svg)](https://github.com/mrvi0/cli-json-fomatter)
[![Status](https://img.shields.io/badge/Status-Passing-orange.svg)](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

[![Fast Startup](https://img.shields.io/badge/Fast%20Startup-No%20npm%20install-brightgreen.svg)](https://github.com/mrvi0/cli-json-fomatter)
[![Minimal Dependencies](https://img.shields.io/badge/Dependencies-jq%20only-orange.svg)](https://stedolan.github.io/jq/)
[![Lightweight](https://img.shields.io/badge/Lightweight-~5KB-blue.svg)](https://github.com/mrvi0/cli-json-fomatter)
[![Linux Native](https://img.shields.io/badge/Linux-Native%20Support-red.svg)](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!