LinuxCommandLibrary

jc

Convert command output to JSON

TLDR

View documentation for the JSON serializer

$ tldr jc.json
copy

View documentation for the autojump alias
$ tldr autojump
copy

SYNOPSIS

command | jc [options] --<parser_name>
jc [options] --<parser_name> <file>
jc --help
jc --version

PARAMETERS

--<parser_name>
    Selects the specific parser to use for the input. For example, --ls parses ls output, --ps parses ps output. A comprehensive list of available parsers can be found using the jc-docs command or online documentation.

-p, --pretty
    Pretty-prints the JSON output with indentation and line breaks for better readability.

--yaml
    Outputs the parsed data in YAML format instead of JSON.

--pickle
    Outputs the parsed data in Python pickle format. Useful for direct consumption in Python scripts.

-r, --raw
    Outputs the raw dictionary from the parser before any post-processing. Useful for debugging or when you need the data as close to the initial parsing as possible.

--mono
    Disables color output from jc, if any. (Synonymous with --disable-color).

--cp
    Copies the original command output into the _raw field of the resulting JSON object. Useful for retaining the source text alongside the parsed data.

-v, --version
    Displays the jc version information and exits.

-h, --help
    Displays the help message and exits, showing available options and basic usage.

DESCRIPTION

jc (JSON Convert) is a powerful command-line tool that transforms the unstructured output of many common Linux commands into structured JSON (or YAML, or Python pickle) format. It acts as a wrapper or a filter, taking the output of a command via standard input (or directly from a file) and processing it through an appropriate parser before emitting the structured data to standard output.

This utility significantly simplifies scripting and automation tasks, allowing developers and system administrators to consume CLI output programmatically without resorting to complex regex parsing or custom scripts. Instead of parsing human-readable text, users can work with predictable JSON objects, making data extraction and manipulation much more robust and efficient. jc supports a vast and growing number of parsers for commands like ls, ps, df, ifconfig, netstat, mount, stat, and many more, making it an invaluable tool in modern DevOps and scripting environments.

CAVEATS

jc relies on specific output formats of the commands it parses. Any significant changes to a command's output format by its maintainers could potentially break the corresponding jc parser until an update is released. It requires Python to run. While highly efficient, parsing very large command outputs can introduce a noticeable overhead.

AVAILABLE PARSERS

jc includes a vast and continuously growing collection of parsers, each specifically designed for a particular command's output (e.g., --ls for ls, --ps for ps, --ip-address for ip address). To view the complete and up-to-date list of supported parsers and their documentation, use the dedicated jc-docs command or refer to the official jc project documentation online.

PIPING INPUT

The most common and effective way to use jc is by piping the standard output of another command into jc's standard input. This allows jc to act as a filter, converting the text stream into a structured JSON stream. For example: ls -l | jc --ls.

FILE INPUT

While primarily used with pipes, jc can also parse the content of a file directly. This is useful if you have saved command output to a file and wish to parse it later. For example: jc --ls my_ls_output.txt.

HISTORY

jc was created by Kelly Brazil to address the widespread need for structured data from standard Linux command-line tools. Its development was driven by the increasing demand for automation, API integration, and programmatic consumption of system information in modern IT environments. Since its inception, jc has rapidly gained traction within the DevOps, system administration, and scripting communities for its ease of use and significant reduction in the complexity of parsing CLI output.

SEE ALSO

jq(1), awk(1), sed(1), grep(1)

Copied to clipboard