jc is a CLI tool and Python library that converts the output of popular command-line tools and file-types to JSON, YAML, or Python dictionaries. This allows for easier parsing in scripts and seamless integration with tools like `jq`. The library is actively maintained with frequent releases, typically on a monthly or bi-monthly cadence.
pip install jcVerified import paths — ran on the pinned version, not inferred.
This quickstart demonstrates how to use `jc` to parse the output of a command-line tool. It captures command output using `subprocess.check_output` and then uses `jc.parse()` with the appropriate parser name ('dig', 'df') to convert it into a Python dictionary or list of dictionaries.
Replace `jc.parse('iso-datetime', ...)` with `jc.parse('datetime-iso', ...)`.Update scripts that expect `size` as a string or in specific units to handle the new integer (byte) format. Perform explicit unit conversion if human-readable output is desired.
Ensure all necessary optional dependencies are installed via `pip install jc[xml]` (if extras are defined) or `pip install <dependency_name>` if you plan to use parsers requiring them. For `xmltodict`, install with `pip install xmltodict`.
Check `jc -hhh` on the command line or refer to the documentation to identify parsers compatible with the `--slurp` option before using it.
Ensure `jc` is installed (`pip install jc`) and that your shell's PATH includes the directory where pip installs executables (e.g., `~/.local/bin` on Linux/macOS or `Scripts` folder in Python installation on Windows). You might need to restart your terminal or source your shell's configuration file (e.g., `source ~/.bashrc` or `source ~/.zshrc`).
Install the `jc` library using pip: `pip install jc`. If you are using virtual environments, ensure your environment is activated before installation. If already installed, verify you are running your script with the correct Python interpreter where `jc` is installed.
When using the `jc` CLI, specify the parser using the `--parser_name` option (e.g., `ls -l | jc --ls`). When using the Python library, ensure you pass the correct parser name as the first argument to `jc.parse()` (e.g., `jc.parse('ls', cmd_output)`).Upgrade `jc` to a version that handles BOMs in CSV files (version 1.22.2 or newer is recommended). `pip install --upgrade jc`. Alternatively, ensure your CSV files do not contain a BOM.