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

parsers.mddocs/

Individual Parsers

Over 240 specialized parsers for converting output from specific commands, file formats, and data patterns to structured JSON. Each parser follows a consistent interface and includes metadata about compatibility and usage.

Parser Interface

All parsers follow the same standard interface pattern:

def parse(
    data: str,
    quiet: bool = False,
    raw: bool = False
) -> Union[Dict[str, Any], List[Dict[str, Any]]]:
    """
    Parse command output or file content into structured JSON.

    Parameters:
    - data: Input string to parse
    - quiet: Suppress warning messages if True
    - raw: Output preprocessed JSON if True

    Returns:
    - Dictionary or List of Dictionaries containing parsed data
    """

# Parser metadata object
info: ParserInfoType  # Contains parser metadata and compatibility information

Parser Categories

System Information Parsers

Parse output from system information and status commands.

Available Parsers:

  • uname - Parse uname command output
  • uptime - Parse uptime command output
  • free - Parse free command output
  • df - Parse df command output
  • mount - Parse mount command output
  • lsblk - Parse lsblk command output
  • dmidecode - Parse dmidecode command output
  • systeminfo - Parse Windows systeminfo command output

Network Parsers

Parse output from network diagnostic and configuration commands.

Available Parsers:

  • dig - Parse dig DNS lookup output
  • host - Parse host DNS lookup output
  • ping - Parse ping command output
  • netstat - Parse netstat command output
  • ss - Parse ss socket statistics output
  • ifconfig - Parse ifconfig network interface output
  • ip-address - Parse ip address command output
  • ip-route - Parse ip route command output
  • arp - Parse arp table output
  • route - Parse route table output

Process and System Monitoring

Parse output from process monitoring and system statistics commands.

Available Parsers:

  • ps - Parse ps process list output
  • top - Parse top command output
  • iostat - Parse iostat I/O statistics
  • vmstat - Parse vmstat virtual memory statistics
  • mpstat - Parse mpstat processor statistics
  • pidstat - Parse pidstat process statistics
  • w - Parse w logged users output
  • who - Parse who logged users output
  • last - Parse last login history output

File System Parsers

Parse file system information and file content.

Available Parsers:

  • ls - Parse ls directory listing output
  • find - Parse find command output
  • file - Parse file type identification output
  • stat - Parse stat file information output
  • lsattr - Parse lsattr file attributes output
  • du - Parse du disk usage output
  • fstab - Parse /etc/fstab file content
  • hosts - Parse /etc/hosts file content

Package Management

Parse output from package management commands.

Available Parsers:

  • apt-cache-show - Parse apt-cache show output
  • apt-get-sqq - Parse apt-get -sqq output
  • dpkg-l - Parse dpkg -l package list
  • rpm-qi - Parse rpm -qi package info
  • pip-list - Parse pip list output
  • pip-show - Parse pip show package details

Configuration Files

Parse various configuration file formats.

Available Parsers:

  • ini - Parse INI configuration files
  • yaml - Parse YAML files
  • xml - Parse XML files
  • csv - Parse CSV files
  • json - Parse JSON files (with validation)
  • toml - Parse TOML files
  • plist - Parse Apple plist files

Security and Certificates

Parse security-related command output and certificate information.

Available Parsers:

  • x509-cert - Parse X.509 certificate information
  • x509-csr - Parse X.509 certificate signing requests
  • gpg - Parse GPG command output
  • ssh-conf - Parse SSH configuration files
  • sshd-conf - Parse SSH daemon configuration

Streaming Parsers

Real-time parsers for continuous data processing (append -s to parser name).

Available Streaming Parsers:

  • ping-s - Stream ping output in real-time
  • syslog-s - Stream syslog entries
  • clf-s - Stream Common Log Format entries
  • csv-s - Stream CSV data
  • top-s - Stream top command output

Universal Parser Utilities

Helper functions for building custom parsers:

# From jc.parsers.universal module
def simple_table_parse(data: Iterable[str]) -> List[Dict]:
    """
    Parse simple tables with no blank cells.
    
    Parameters:
    - data: Text data split into lines, with item 0 as header row
    
    Returns:
    - List of dictionaries representing table rows
    """

def sparse_table_parse(data: Iterable[str], delim: str = '\u2063') -> List[Dict]:
    """
    Parse tables that may contain blank cells.
    
    Parameters:
    - data: Text data split into lines
    - delim: Delimiter character for sparse fields
    
    Returns:
    - List of dictionaries representing table rows
    """

Usage Examples

Direct Parser Access

# Method 1: Via main parse function
import jc
data = jc.parse('dig', dig_output)

# Method 2: Via get_parser
jc_dig = jc.get_parser('dig')
data = jc_dig.parse(dig_output)

# Method 3: Direct module import
import jc.parsers.dig
data = jc.parsers.dig.parse(dig_output)

Streaming Parser Usage

import jc

# Parse streaming data
ping_lines = ['PING example.com (93.184.216.34): 56 data bytes',
              '64 bytes from 93.184.216.34: icmp_seq=0 ttl=56 time=11.632 ms']

ping_stream = jc.parse('ping-s', ping_lines)
for parsed_line in ping_stream:
    if parsed_line.get('time_ms'):
        print(f"Response time: {parsed_line['time_ms']} ms")

Parser Information

import jc

# Get parser metadata
dig_info = jc.parser_info('dig')
print(f"Description: {dig_info['description']}")
print(f"Compatible: {dig_info['compatible']}")
print(f"Version: {dig_info['version']}")

# Check if parser supports streaming
if dig_info.get('streaming'):
    print("Supports streaming")

# Get all parsers supporting a specific tag
all_info = jc.all_parser_info()
slurpable_parsers = [p['name'] for p in all_info if 'slurpable' in p.get('tags', [])]

Custom Parser Development

# Example parser structure (for plugin development)
"""jc - JSON Convert my_custom_parser"""

info = {
    'name': 'my_custom',
    'description': 'Custom parser for my data format',
    'author': 'Your Name',
    'version': '1.0',
    'compatible': ['linux', 'darwin', 'win32'],
    'tags': ['command']
}

def parse(data, quiet=False, raw=False):
    \"\"\"Parse custom data format\"\"\"
    # Parser implementation
    return parsed_data

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