Converts the output of popular command-line tools and file-types to JSON.
npx @tessl/cli install tessl/pypi-jc@1.25.0A comprehensive command-line utility and Python library that converts the output of popular CLI tools, file formats, and common string patterns to JSON format for easier parsing and processing in scripts and automation workflows. It supports over 240 different parsers for commands like dig, ps, ls, netstat, and many others, enabling seamless integration with JSON processing tools like jq.
pip install jcimport jcFor direct parser access:
import jc.parsers.dig # Example: access dig parser directlyFor CLI usage:
from jc import cliimport jc
import subprocess
# Parse command output using high-level API
cmd_output = subprocess.check_output(['dig', 'example.com'], text=True)
data = jc.parse('dig', cmd_output)
print(data[0]['id']) # Access parsed data
# Get parser module for direct use
jc_dig = jc.get_parser('dig')
data = jc_dig.parse(cmd_output)
# Direct parser module access
import jc.parsers.dig
data = jc.parsers.dig.parse(cmd_output)# Parse command output via pipe
dig example.com | jc --dig
# Use magic syntax for direct command execution
jc dig example.com
# Stream processing for large datasets
tail -f /var/log/syslog | jc --syslog-sThe jc library is organized around a plugin-based parser system:
High-level parsing functions and parser discovery utilities that provide the main interface for using jc programmatically.
def parse(parser_mod_name: Union[str, ModuleType], data: Union[str, bytes, Iterable[str]], quiet: bool = False, raw: bool = False, ignore_exceptions: Optional[bool] = None, **kwargs) -> Union[JSONDictType, List[JSONDictType], Iterator[JSONDictType]]: ...
def get_parser(parser_mod_name: Union[str, ModuleType]) -> ModuleType: ...
def parser_mod_list(show_hidden: bool = False, show_deprecated: bool = False) -> List[str]: ...
def slurpable_parser_mod_list(show_hidden: bool = False, show_deprecated: bool = False) -> List[str]: ...
def parser_info(parser_mod_name: Union[str, ModuleType], documentation: bool = False) -> ParserInfoType: ...Over 240 specialized parsers for converting output from specific commands, file formats, and data patterns to structured JSON.
# Each parser module contains:
def parse(data: str, quiet: bool = False, raw: bool = False) -> Union[Dict, List[Dict]]: ...
# Parser information object
info = ParserInfoType # Contains metadata, version, compatibility infoReal-time parsing capabilities for processing continuous data streams, with built-in error handling and metadata generation.
def streaming_input_type_check(data: Iterable[Union[str, bytes]]) -> None: ...
def stream_success(output_line: JSONDictType, ignore_exceptions: bool) -> JSONDictType: ...
def add_jc_meta(func: F) -> F: ... # Decorator for streaming parsersFull command-line interface with extensive options, magic syntax, and multiple output formats.
class JcCli:
def __init__(self) -> None: ...
# Handles all CLI operations, argument parsing, and output formatting
def main() -> None: ... # CLI entry pointUtility functions for text processing, validation, and type definitions used throughout the library.
# Exception classes
class ParseError(Exception): ...
class LibraryNotInstalled(Exception): ...
# Type definitions
JSONDictType = Dict[str, Any]
ParserInfoType = TypedDict # Comprehensive parser metadata structurefrom typing import Dict, List, Union, Optional, Iterable, Iterator, TypedDict, Any
from types import ModuleType
JSONDictType = Dict[str, Any]
CustomColorType = Dict[Any, str]
StreamingOutputType = Iterator[Union[JSONDictType, Tuple[BaseException, str]]]
# Parser metadata structure (Python 3.8+)
ParserInfoType = TypedDict('ParserInfoType', {
"name": str,
"argument": str,
"version": str,
"description": str,
"author": str,
"author_email": str,
"compatible": List[str],
"magic_commands": List[str],
"tags": List[str],
"documentation": str,
"streaming": bool,
"plugin": bool,
"hidden": bool,
"deprecated": bool
}, total=False)