$ show kellyjonbrazil/jc
jc (JSON Convert) is a mature Python library and CLI tool that converts the output of over 150 command-line tools, system files, and common data formats into structured JSON. It operates both as a piped command-line utility (`jc <command>`) and as a programmable Python module (`jc.parse('parser_name', data)`), enabling seamless integration with jq, scripting, and automation pipelines. The architecture follows a consistent parser pattern: each parser module defines an `info` metadata class and a `parse(data, raw, quiet)` function, with optional `_process()` for type coercion. Streaming parsers (suffixed `_s`) use generator-based patterns for real-time output. The library includes vendored dependencies for ASN.1, plist, EDID, and TOML parsing, and supports cross-platform execution across Linux, macOS, FreeBSD, and Windows. The primary data flow is stdin or file input → parser module → structured dict/list output (JSON or YAML). Key entry points include the CLI (`jc/cli.py`), the library API (`jc/lib.py`), and individual parser modules under `jc/parsers/`. The project maintains an extensive test suite with fixtures captured from multiple OS versions, ensuring robustness against command output variations. It also provides shell completions, a plugin system for custom parsers, and documentation generation scripts. While the codebase is well-engineered with clean abstractions, the sheer number of parsers and reliance on vendored libraries introduce moderate maintenance surface area.
The LLM identified 3 files worth highlighting for reuse:
Provides `simple_table_parse()` and `sparse_table_parse()` functions that convert aligned text tables (space-separated, multi-line headers) into lists of dictionaries. This is a reusable pattern for any project that needs to parse columnar CLI output or log files without a dedicated parser. It handles header normalization, type inference, and edge cases like missing columns. The module depends only on `jc.utils` and `jc.exceptions`, making it extractable with minimal adaptation.
Implements a decorator-based streaming parser framework using `@add_jc_meta` and helper functions like `streaming_input_type_check()`, `raise_or_yield()`, and `stream_success()/stream_error()`. This pattern allows parsers to yield JSON objects line-by-line from iterable input, supporting real-time processing with optional exception suppression. The module is self-contained (imports only `jc.utils` and `jc.exceptions`) and can be extracted to add streaming capabilities to any text-parsing library.
A collection of reusable utility functions for data conversion and validation: `convert_to_int()`, `convert_to_float()`, `convert_to_bool()`, `convert_size_to_int()`, `timestamp()` (with naive/UTC epoch and ISO formats), `compatibility()` (OS/platform checks), `input_type_check()` (data type validation), `has_data()` (empty input detection), and `normalize_key()` (string key cleaning). These functions are used across all parsers and can be extracted as a standalone utility library for any Python project dealing with text-to-data conversion.