Converts the output of popular command-line tools and file-types to JSON.
—
Full command-line interface with extensive options, magic syntax, and multiple output formats. The CLI provides both traditional piped input processing and direct command execution capabilities.
def main() -> None:
"""
Main CLI entry point function.
Handles argument parsing, command execution, and output formatting.
Called when running 'jc' command or 'python -m jc'.
"""The main CLI handler class that manages all command-line operations.
class JcCli:
"""
Main CLI interface class handling argument parsing and command execution.
"""
def __init__(self) -> None:
"""
Initialize CLI handler with default settings.
Sets up internal state for:
- Input/output data handling
- Parser module management
- Formatting and display options
- Command execution options
"""class info:
"""Package metadata and version information."""
version: str = "1.25.5"
description: str = "JSON Convert"
author: str = "Kelly Brazil"
author_email: str = "kellyjonbrazil@gmail.com"
website: str = "https://github.com/kellyjonbrazil/jc"
copyright: str = "© 2019-2025 Kelly Brazil"
license: str = "MIT License"# Parse command output via pipe
command | jc --parser-name
# Examples
dig example.com | jc --dig
ps aux | jc --ps
netstat -rn | jc --netstat# Execute commands directly with jc
jc command [arguments]
# Examples
jc dig example.com
jc ps aux
jc netstat -rn
jc ls -la /etc# Use specific parser
jc --dig dig example.com
jc --ps ps aux
# List available parsers
jc -a
jc --about
# Get parser documentation
jc -h --dig
jc --help --ps# Standard JSON output
jc dig example.com
# Pretty-printed JSON
jc -p dig example.com
jc --pretty dig example.com
# Raw (preprocessed) JSON
jc -r dig example.com
jc --raw dig example.com# YAML output
jc -y dig example.com
jc --yaml dig example.com
# Monochrome output (no colors)
jc -m dig example.com
jc --monochrome dig example.com
# Force color output
jc -C dig example.com
jc --force-color dig example.com# Use streaming parser
tail -f /var/log/syslog | jc --syslog-s
# Stream with error handling
tail -f /var/log/messages | jc --syslog-s --ignore-exceptions
# Unbuffer output for real-time processing
tail -f access.log | jc --clf-s --unbuffer# Slice output (Python slice syntax)
jc dig example.com -s '[0]' # First element
jc ps aux -s '[0:5]' # First 5 elements
jc ls -la -s '[-3:]' # Last 3 elements
# Combine with external tools
jc ps aux | jq '.[] | select(.command | contains("python"))'# Quiet mode (suppress warnings)
jc -q dig example.com
jc --quiet dig example.com
# Debug mode
jc -d dig example.com
jc --debug dig example.example
# Verbose debug
jc -dd dig example.com
jc --debug --debug dig example.com# Slurp mode (combine multiple JSON outputs into array)
# Only available for parsers that support slurping
cat file1.json file2.json | jc --slurp --json
# Process multiple files
for file in *.csv; do
cat "$file" | jc --csv > "${file%.csv}.json"
doneMany parsers accept additional options passed through the CLI:
# Examples of parser-specific options
jc --csv --delimiter=';' < data.csv
jc --ini --duplicate-keys < config.ini
jc --timestamp --format='%Y-%m-%d %H:%M:%S' < timestamps.txt# Generate bash completion script
jc --bash-completion
# Install completion
jc --bash-completion > /etc/bash_completion.d/jc# Generate zsh completion script
jc --zsh-completion
# Install completion
jc --zsh-completion > ~/.zsh/completions/_jc#!/bin/bash
# Extract specific data from system commands
# Get total memory from free command
total_mem=$(jc free -h | jq -r '.[] | select(.type=="Mem") | .total')
# Get running processes count
process_count=$(jc ps aux | jq 'length')
# Get disk usage over 80%
high_usage=$(jc df -h | jq '.[] | select(.use_percent > 80) | .filesystem')
echo "Total Memory: $total_mem"
echo "Running Processes: $process_count"
echo "High Disk Usage: $high_usage"# Real-time log analysis
tail -f /var/log/nginx/access.log | \
jc --clf-s | \
jq -r 'select(.status_code >= 400) | "\(.date_time) \(.status_code) \(.request)"'# Monitor system metrics
watch -n 5 'jc ps aux | jq "sort_by(.percent_cpu) | reverse | .[0:5] | .[] | \"\(.percent_cpu)% \(.command)\""'The CLI provides comprehensive error handling and user feedback:
# Invalid parser
jc --invalid-parser command
# Error: "invalid-parser" is not found or is not a valid parser module.
# Missing input
jc --dig
# Error: No input data
# Parser-specific errors
echo "invalid data" | jc --json
# Warning: JSON parser error (with --quiet suppresses warnings)0 - Successful execution100 - General error (invalid arguments, parser errors, etc.)101-255 - Parser-specific error codes# Customize jc behavior via environment variables
export JC_COLORS="red,green,blue" # Custom color scheme
export JC_INDENT=4 # Default JSON indentation
export JC_QUIET=1 # Default quiet modeInstall with Tessl CLI
npx tessl i tessl/pypi-jc