jc

Compare original and translation side by side

🇺🇸

Original

English
🇨🇳

Translation

Chinese

jc

jc

JSONifies the output of CLI tools and file-types for easier parsing.
将CLI工具和各类文件的输出转换为JSON格式,便于解析。

Basic Usage

基本用法

bash
command | jc --parser          # Pipe output
jc command                    # Magic syntax
jc --help                     # List all parsers
jc --help --parser            # Parser docs
bash
command | jc --parser          # Pipe output
jc command                    # Magic syntax
jc --help                     # List all parsers
jc --help --parser            # Parser docs

Examples

示例

bash
dig example.com | jc --dig | jq '.answer[].data'
ps aux | jc --ps
ifconfig | jc --ifconfig
bash
dig example.com | jc --dig | jq '.answer[].data'
ps aux | jc --ps
ifconfig | jc --ifconfig

Parsers

解析器

CategoryParsers
System
ps
,
top
,
free
,
df
,
du
,
ls
,
stat
,
uptime
Network
dig
,
ping
,
traceroute
,
netstat
,
ss
,
ifconfig
Files
ls
,
find
,
stat
,
file
,
mount
,
fstab
Packages
dpkg -l
,
rpm -qi
,
pacman
,
brew
Logs
syslog
,
clf
(Common Log Format)
Dev
git log
,
docker ps
,
kubectl
分类解析器
系统
ps
,
top
,
free
,
df
,
du
,
ls
,
stat
,
uptime
网络
dig
,
ping
,
traceroute
,
netstat
,
ss
,
ifconfig
文件
ls
,
find
,
stat
,
file
,
mount
,
fstab
软件包
dpkg -l
,
rpm -qi
,
pacman
,
brew
日志
syslog
,
clf
(Common Log Format)
开发
git log
,
docker ps
,
kubectl

Options

选项

FlagDescription
-p
Pretty format JSON
-r
Raw output (less processed)
-u
Unbuffered output
-q
Quiet (suppress warnings)
-d
Debug mode
-y
YAML output
-M
Add metadata
-s
Slurp multi-line input
参数描述
-p
格式化输出JSON
-r
原始输出(处理较少)
-u
无缓冲输出
-q
静默模式(抑制警告)
-d
调试模式
-y
输出YAML格式
-M
添加元数据
-s
读取多行输入

Slicing

切片操作

Skip lines:
START:STOP
syntax
bash
cat file.txt | jc 1:-1 --parser  # Skip first/last lines
跳过行:
START:STOP
语法
bash
cat file.txt | jc 1:-1 --parser  # Skip first/last lines

Slurp Mode

批量读取模式

For multi-line parsers:
--slurp
outputs array
bash
cat ips.txt | jc --slurp --ip-address
对于多行解析器:
--slurp
输出数组
bash
cat ips.txt | jc --slurp --ip-address

Python Library

Python库

python
import jc
python
import jc

Parse command output

Parse command output

data = jc.parse('dig', output_string)
data = jc.parse('dig', output_string)

Or parse directly

Or parse directly

data = jc.parsers.dig.parse(output_string)
undefined
data = jc.parsers.dig.parse(output_string)
undefined

Tips

小贴士

  • Magic syntax:
    jc command
    auto-detects parser
  • Use
    jq
    for processing:
    jc cmd | jq '.field'
  • --slurp
    for multiple items per file
  • Streaming parsers for large outputs
  • Python lib returns dict/list, not JSON
  • 魔法语法:
    jc command
    自动检测解析器
  • 结合
    jq
    进行处理:
    jc cmd | jq '.field'
  • 处理多条目文件时使用
    --slurp
  • 流式解析器处理大体积输出
  • Python库返回字典/列表,而非JSON格式

Related Skills

相关工具

  • nu-shell: Alternative structured data processing
  • toon: Compact JSON representation
  • nu-shell:可替代的结构化数据处理工具
  • toon:紧凑的JSON表示格式