or run

npx @tessl/cli init
Log in

Version

Tile

Overview

Evals

Files

docs

cli.mdcore-api.mdindex.mdparsers.mdstreaming.mdutilities.md
tile.json

tessl/pypi-jc

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

Workspace
tessl
Visibility
Public
Created
Last updated
Describes
pypipkg:pypi/jc@1.25.x

To install, run

npx @tessl/cli install tessl/pypi-jc@1.25.0

index.mddocs/

jc - JSON Convert

A 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.

Package Information

  • Package Name: jc
  • Language: Python
  • Installation: pip install jc
  • Version: 1.25.5
  • License: MIT

Core Imports

import jc

For direct parser access:

import jc.parsers.dig  # Example: access dig parser directly

For CLI usage:

from jc import cli

Basic Usage

Library Usage

import 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)

CLI Usage

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

Architecture

The jc library is organized around a plugin-based parser system:

  • Core API: High-level functions for parsing and parser discovery
  • Parser Registry: Centralized system managing 240+ built-in parsers
  • Plugin System: User-extensible parser loading from custom directories
  • Streaming Support: Real-time processing of continuous data streams
  • CLI Interface: Full command-line tool with magic syntax and formatting options
  • Type System: Comprehensive type definitions for all components

Capabilities

Core API Functions

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: ...

Core API

Individual Parsers

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 info

Parsers

Streaming Parsers

Real-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 parsers

Streaming

CLI Interface

Full 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 point

CLI Interface

Utilities and Types

Utility 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 structure

Utilities

Types

from 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)