Skip to content

jkit cut

把深层嵌套的 JSON 折叠成简洁摘要。看一坨巨大的 API 响应时,先用它扫一眼整体结构特别舒服。

bash
jkit cut <depth>   # 全名
jkit c <depth>     # 短别名

命令格式

jkit cut [<depth>]
jkit c   [<depth>]
参数说明
<depth>最大渲染深度。超过此深度的节点会被替换成单行摘要。可选 —— 不传时不做任何折叠。

stdin 或剪贴板读取 —— 详见 输入来源

行为说明

  • <depth> 层以内正常渲染对象和数组。
  • 到达 <depth> 时,嵌套对象替换为 { N items dict }、数组替换为 [ N items array ]
  • 对象键按字典序输出,相同输入永远得到相同结果。两份 payload 的 diff 干干净净。

示例

depth = 0:全部折叠

bash
> echo '{"a":1,"b":[2,3]}' | jkit c 0

{ 2 items dict }

depth = 1:看顶层结构

bash
> echo '{"meta":{"a":1,"b":2},"items":[1,2,3]}' | jkit c 1

{
    "items": [ 3 items array ],
    "meta": { 2 items dict }
}

depth = 2:再深一层

bash
> echo '{"code":0,"message":"success","result":{"main_section":{"id":1,"title":"x"},"section":[{"id":2}]}}' | jkit c 2

{
    "code": 0,
    "message": "success",
    "result": {
        "main_section": { 2 items dict },
        "section": [ 1 items array ]
    }
}

不传参数:完整树 + 排序键

bash
> echo '{"b":1,"a":2,"c":3}' | jkit c

{
    "a": 2,
    "b": 1,
    "c": 3
}

错误处理

bash
> echo '{}' | jkit c abc
jkit: invalid depth "abc": strconv.Atoi: parsing "abc": invalid syntax

> echo '{}' | jkit c -1
jkit: depth must be non-negative, got -1