CtrlK
BlogDocsLog inGet started
Tessl Logo

tessl/pypi-jc

Converts the output of popular command-line tools and file-types to JSON.

Pending
Overview
Eval results
Files

cli.mddocs/

CLI Interface

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.

CLI Entry Point

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

CLI Class

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

Package Information Class

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"

Command-Line Usage Patterns

Basic Parsing (Pipe Mode)

# Parse command output via pipe
command | jc --parser-name

# Examples
dig example.com | jc --dig
ps aux | jc --ps
netstat -rn | jc --netstat

Magic Syntax (Direct Execution)

# Execute commands directly with jc
jc command [arguments]

# Examples  
jc dig example.com
jc ps aux
jc netstat -rn
jc ls -la /etc

Parser Selection

# 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

Output Format Options

JSON Output (Default)

# 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

Alternative Formats

# 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

Streaming Options

# 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

Advanced Options

Slicing and Filtering

# 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"))'

Debugging and Verbosity

# 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

Batch Processing

# 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"
done

Parser-Specific Options

Many 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

Shell Completions

Bash Completion

# Generate bash completion script  
jc --bash-completion

# Install completion
jc --bash-completion > /etc/bash_completion.d/jc

Zsh Completion

# Generate zsh completion script
jc --zsh-completion

# Install completion  
jc --zsh-completion > ~/.zsh/completions/_jc

Integration Examples

Script Integration

#!/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"

Log Analysis Pipeline

# 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)"'

System Monitoring

# Monitor system metrics
watch -n 5 'jc ps aux | jq "sort_by(.percent_cpu) | reverse | .[0:5] | .[] | \"\(.percent_cpu)% \(.command)\""'

Error Handling

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)

Exit Codes

  • 0 - Successful execution
  • 100 - General error (invalid arguments, parser errors, etc.)
  • 101-255 - Parser-specific error codes

Environment Variables

# 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 mode

Install with Tessl CLI

npx tessl i tessl/pypi-jc

docs

cli.md

core-api.md

index.md

parsers.md

streaming.md

utilities.md

tile.json