jc
Compare original and translation side by side
🇺🇸
Original
English🇨🇳
Translation
Chinesejc
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 docsbash
command | jc --parser # Pipe output
jc command # Magic syntax
jc --help # List all parsers
jc --help --parser # Parser docsExamples
示例
bash
dig example.com | jc --dig | jq '.answer[].data'
ps aux | jc --ps
ifconfig | jc --ifconfigbash
dig example.com | jc --dig | jq '.answer[].data'
ps aux | jc --ps
ifconfig | jc --ifconfigParsers
解析器
| Category | Parsers |
|---|---|
| System | |
| Network | |
| Files | |
| Packages | |
| Logs | |
| Dev | |
| 分类 | 解析器 |
|---|---|
| 系统 | |
| 网络 | |
| 文件 | |
| 软件包 | |
| 日志 | |
| 开发 | |
Options
选项
| Flag | Description |
|---|---|
| Pretty format JSON |
| Raw output (less processed) |
| Unbuffered output |
| Quiet (suppress warnings) |
| Debug mode |
| YAML output |
| Add metadata |
| Slurp multi-line input |
| 参数 | 描述 |
|---|---|
| 格式化输出JSON |
| 原始输出(处理较少) |
| 无缓冲输出 |
| 静默模式(抑制警告) |
| 调试模式 |
| 输出YAML格式 |
| 添加元数据 |
| 读取多行输入 |
Slicing
切片操作
Skip lines: syntax
START:STOPbash
cat file.txt | jc 1:-1 --parser # Skip first/last lines跳过行: 语法
START:STOPbash
cat file.txt | jc 1:-1 --parser # Skip first/last linesSlurp Mode
批量读取模式
For multi-line parsers: outputs array
--slurpbash
cat ips.txt | jc --slurp --ip-address对于多行解析器: 输出数组
--slurpbash
cat ips.txt | jc --slurp --ip-addressPython Library
Python库
python
import jcpython
import jcParse 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)
undefineddata = jc.parsers.dig.parse(output_string)
undefinedTips
小贴士
- Magic syntax: auto-detects parser
jc command - Use for processing:
jqjc cmd | jq '.field' - for multiple items per file
--slurp - Streaming parsers for large outputs
- Python lib returns dict/list, not JSON
- 魔法语法:自动检测解析器
jc command - 结合进行处理:
jqjc cmd | jq '.field' - 处理多条目文件时使用
--slurp - 流式解析器处理大体积输出
- Python库返回字典/列表,而非JSON格式
Related Skills
相关工具
- nu-shell: Alternative structured data processing
- toon: Compact JSON representation
- nu-shell:可替代的结构化数据处理工具
- toon:紧凑的JSON表示格式