json-flat-tool
Compare original and translation side by side
🇺🇸
Original
English🇨🇳
Translation
ChineseJSON Flat Tool
JSON扁平工具
A single-script tool () for viewing, inspecting, and editing JSON data.
jstool.pyScript path:
~/.claude/skills/json-flat-tool/jstool.py一款单脚本工具(),用于查看、检查和编辑JSON数据。
jstool.py脚本路径:
~/.claude/skills/json-flat-tool/jstool.pyInvocation
调用方式
bash
python3 ~/.claude/skills/json-flat-tool/jstool.py <command> [args]bash
python3 ~/.claude/skills/json-flat-tool/jstool.py <command> [args]Commands
命令列表
| Command | Description |
|---|---|
| Flat path/type/value display |
| Infer JSON Schema Draft 7 |
| Set a field value |
| Same, B-style syntax |
| Insert before array element |
| Insert after array element |
| Delete a key or element |
| Set a field to null |
| Deep-clone a subtree to a new path |
| Deep-merge a JSON file into a path |
| Search paths and values by regex or glob |
Omit to read from stdin.
[file]| 命令 | 描述 |
|---|---|
| 以扁平路径/类型/值形式展示 |
| 推断JSON Schema Draft 7格式的Schema |
| 设置字段值 |
| 功能同上,B风格语法 |
| 在数组元素前插入内容 |
| 在数组元素后插入内容 |
| 删除键或元素 |
| 将字段设为null |
| 将子树深度克隆到新路径 |
| 将JSON文件深度合并到指定路径 |
| 通过正则表达式或通配符搜索路径和值 |
省略则从stdin读取数据。
[file]view Options
view命令参数
| Flag | Unit | Description |
|---|---|---|
| — | Schema mode: collapse |
| — | Filter: show only this path and its children |
| rows | Show at most N rows |
| rows | Skip first N rows |
| elements | Skip first N array elements (use with |
| elements | Show at most N array elements (use with |
-E-L| 参数 | 单位 | 描述 |
|---|---|---|
| — | Schema模式:折叠 |
| — | 过滤:仅显示该路径及其子节点 |
| 行数 | 最多显示N行 |
| 行数 | 跳过前N行 |
| 元素数 | 跳过前N个数组元素(需配合 |
| 元素数 | 最多显示N个数组元素(需配合 |
-E-LEdit flags
编辑参数
- — Force: apply change to file. Default is preview-only.
-f - Without : shows a color-annotated diff of the original JSON with
-funderline markers at the exact change position.~~~~~
- — 强制:将更改应用到文件。默认仅预览。
-f - 不使用时:显示原始JSON与更改后的彩色标注差异,在确切更改位置用
-f下划线标记。~~~~~
Path syntax
路径语法
root root node
count root-level key
users[0] array element
users[0].name nested key
root[0].key root-array element keyroot 根节点
count 根级键
users[0] 数组元素
users[0].name 嵌套键
root[0].key 根数组元素的键Value parsing
值解析规则
Values are parsed as JSON first, then fall back to plain string:
Alice → string
42 → integer
3.14 → number
true / false → boolean
null → null
'{"k":"v"}' → object
'[1,2,3]' → array
@path/to.json → read value from file值会先按JSON格式解析,解析失败则 fallback 为普通字符串:
Alice → 字符串
42 → 整数
3.14 → 数字
true / false → 布尔值
null → null
'{"k":"v"}' → 对象
'[1,2,3]' → 数组
@path/to.json → 从文件读取值Output format (view)
输出格式(view命令)
root object
users array
users[0] object
users[0].name string Alice
users[0].age integer 30
users[1].age integer (null) ← magenta: null with inferred type
orphan unknown (null) ← red: null, type unknown
meta object (empty) ← dim: empty containerColors: cyan = path, yellow = type, green = value,
magenta = inferred null, red = unknown/delete, dim = empty.
root object
users array
users[0] object
users[0].name string Alice
users[0].age integer 30
users[1].age integer (null) ← 品红色:带推断类型的null
orphan unknown (null) ← 红色:null,类型未知
meta object (empty) ← 暗色:空容器颜色说明:青色=路径,黄色=类型,绿色=值,
品红色=推断类型的null,红色=未知/已删除,暗色=空容器。
Workflow
使用流程
Explore a JSON file
探索JSON文件
bash
undefinedbash
undefinedQuick structure overview
快速查看结构概览
python3 ~/.claude/skills/json-flat-tool/jstool.py view data.json -s
python3 ~/.claude/skills/json-flat-tool/jstool.py view data.json -s
Filter to a nested array, element-aware pagination
过滤到嵌套数组,按元素分页
python3 ~/.claude/skills/json-flat-tool/jstool.py view data.json -F "data[0].bids" -E 5 -L 3
python3 ~/.claude/skills/json-flat-tool/jstool.py view data.json -F "data[0].bids" -E 5 -L 3
Infer JSON Schema Draft 7
推断JSON Schema Draft 7格式
python3 ~/.claude/skills/json-flat-tool/jstool.py schema data.json --title "My API"
undefinedpython3 ~/.claude/skills/json-flat-tool/jstool.py schema data.json --title "My API"
undefinedEdit a JSON file
编辑JSON文件
bash
undefinedbash
undefinedPreview change (default)
预览更改(默认)
python3 ~/.claude/skills/json-flat-tool/jstool.py set users[0].name Bob data.json
python3 ~/.claude/skills/json-flat-tool/jstool.py set users[0].name Bob data.json
Apply change
应用更改
python3 ~/.claude/skills/json-flat-tool/jstool.py set users[0].name Bob data.json -f
python3 ~/.claude/skills/json-flat-tool/jstool.py set users[0].name Bob data.json -f
B-style
B风格语法
python3 ~/.claude/skills/json-flat-tool/jstool.py "users[0].name" = Bob data.json -f
python3 ~/.claude/skills/json-flat-tool/jstool.py "users[0].name" = Bob data.json -f
Insert / delete
插入 / 删除
python3 ~/.claude/skills/json-flat-tool/jstool.py before users[1] '{"name":"Eve"}' data.json -f
python3 ~/.claude/skills/json-flat-tool/jstool.py del users[2] data.json -f
python3 ~/.claude/skills/json-flat-tool/jstool.py set-null users[0].age data.json -f
undefinedpython3 ~/.claude/skills/json-flat-tool/jstool.py before users[1] '{"name":"Eve"}' data.json -f
python3 ~/.claude/skills/json-flat-tool/jstool.py del users[2] data.json -f
python3 ~/.claude/skills/json-flat-tool/jstool.py set-null users[0].age data.json -f
undefinedSet value from file (@file
)
@file从文件设置值(@file
语法)
@filebash
undefinedbash
undefinedWrite a complex object to a file, then set it at a path
将复杂对象写入文件,然后设置到指定路径
python3 ~/.claude/skills/json-flat-tool/jstool.py set provider.openai @/tmp/openai.json config.json -f
undefinedpython3 ~/.claude/skills/json-flat-tool/jstool.py set provider.openai @/tmp/openai.json config.json -f
undefinedClone a subtree (copy
)
copy克隆子树(copy
命令)
copybash
undefinedbash
undefinedClone an existing model as the base for a new one (preview)
克隆现有模型作为新模型的基础(预览)
python3 ~/.claude/skills/json-flat-tool/jstool.py copy
provider.google.models.antigravity-gemini-3-pro
provider.google.models.my-new-model
config.json
provider.google.models.antigravity-gemini-3-pro
provider.google.models.my-new-model
config.json
python3 ~/.claude/skills/json-flat-tool/jstool.py copy
provider.google.models.antigravity-gemini-3-pro
provider.google.models.my-new-model
config.json
provider.google.models.antigravity-gemini-3-pro
provider.google.models.my-new-model
config.json
Apply
应用克隆
python3 ~/.claude/skills/json-flat-tool/jstool.py copy
provider.google.models.antigravity-gemini-3-pro
provider.google.models.my-new-model
config.json -f
provider.google.models.antigravity-gemini-3-pro
provider.google.models.my-new-model
config.json -f
undefinedpython3 ~/.claude/skills/json-flat-tool/jstool.py copy
provider.google.models.antigravity-gemini-3-pro
provider.google.models.my-new-model
config.json -f
provider.google.models.antigravity-gemini-3-pro
provider.google.models.my-new-model
config.json -f
undefinedDeep-merge a patch file (merge
)
merge深度合并补丁文件(merge
命令)
mergebash
undefinedbash
undefinedpatch.json only needs to contain the fields to add/update
patch.json只需包含要添加/更新的字段
preview: shows which keys are added (+) and updated (~)
预览:显示哪些键是新增(+)和更新(~)的
python3 ~/.claude/skills/json-flat-tool/jstool.py merge provider.google.models /tmp/new-models.json config.json
python3 ~/.claude/skills/json-flat-tool/jstool.py merge provider.google.models /tmp/new-models.json config.json
Apply
应用合并
python3 ~/.claude/skills/json-flat-tool/jstool.py merge provider.google.models /tmp/new-models.json config.json -f
undefinedpython3 ~/.claude/skills/json-flat-tool/jstool.py merge provider.google.models /tmp/new-models.json config.json -f
undefinedFind nodes by pattern (find
)
find按模式查找节点(find
命令)
findbash
undefinedbash
undefinedRegex search in both paths and values (default)
默认:在路径和值中进行正则搜索
python3 ~/.claude/skills/json-flat-tool/jstool.py find apiKey config.json
python3 ~/.claude/skills/json-flat-tool/jstool.py find apiKey config.json
Search path only (-k), value only (-v)
仅搜索路径(-k),仅搜索值(-v)
python3 ~/.claude/skills/json-flat-tool/jstool.py find apiKey config.json -k
python3 ~/.claude/skills/json-flat-tool/jstool.py find "sk-.*" config.json -v
python3 ~/.claude/skills/json-flat-tool/jstool.py find apiKey config.json -k
python3 ~/.claude/skills/json-flat-tool/jstool.py find "sk-.*" config.json -v
Case-insensitive
大小写不敏感
python3 ~/.claude/skills/json-flat-tool/jstool.py find "APIKEY" config.json -k -i
python3 ~/.claude/skills/json-flat-tool/jstool.py find "APIKEY" config.json -k -i
Glob mode (full-string wildcard, use * to match anywhere)
通配符模式(全字符串通配符,用*匹配任意位置)
python3 ~/.claude/skills/json-flat-tool/jstool.py find "api" config.json -k -g -i
**find options**:
| Flag | Description |
|------|-------------|
| `-k` | Match path only |
| `-v` | Match value only |
| `-i` | Case-insensitive |
| `-g` | Glob mode (fnmatch full-string wildcard instead of regex) |
`-k` and `-v` are mutually exclusive. Without either flag, both path and value are searched.python3 ~/.claude/skills/json-flat-tool/jstool.py find "api" config.json -k -g -i
**find命令参数**:
| 参数 | 描述 |
|------|-------------|
| `-k` | 仅匹配路径 |
| `-v` | 仅匹配值 |
| `-i` | 大小写不敏感 |
| `-g` | 通配符模式(使用fnmatch全字符串通配符,而非正则) |
`-k`和`-v`互斥。若不指定两者,则同时搜索路径和值。Inline / piped JSON
内联/管道JSON数据
bash
echo '{"name":"Alice"}' | python3 ~/.claude/skills/json-flat-tool/jstool.py view
curl https://api.example.com/data | python3 ~/.claude/skills/json-flat-tool/jstool.py schemabash
echo '{"name":"Alice"}' | python3 ~/.claude/skills/json-flat-tool/jstool.py view
curl https://api.example.com/data | python3 ~/.claude/skills/json-flat-tool/jstool.py schemaNotes
注意事项
- /
beforeonly apply to array elements, not object keys.after - To add a new key to an object, use .
set - without a file path prints modified JSON to stdout.
-f - /
-Erequire-Lpointing to an array path.-F - Array sampling for schema inference: up to 20 elements.
- in schema = fields present and non-empty in all sampled elements.
required - syntax works with
@fileand B-style (set);=always takes a file path directly.merge - performs a deep clone — mutations to the copy do not affect the source.
copy - for non-dict targets replaces the value entirely (patch wins).
merge - uses
find -g(full-string wildcard): usefnmatchnot*api*for substring matching.api* - without
finduses Python-g(substring regex by default).re.search
- /
before仅适用于数组元素,不适用于对象键。after - 要为对象添加新键,请使用命令。
set - 不带文件路径使用会将修改后的JSON输出到stdout。
-f - /
-E需要配合指向数组路径的-L参数使用。-F - Schema推断的数组采样:最多20个元素。
- Schema中的字段=所有采样元素中都存在且非空的字段。
required - 语法适用于
@file和B风格(set)命令;=始终直接接收文件路径。merge - 执行深度克隆——对副本的修改不会影响源数据。
copy - 针对非字典目标的操作会完全替换值(补丁优先级更高)。
merge - 使用
find -g(全字符串通配符):若要匹配子串,请使用fnmatch而非*api*。api* - 不带的
-g使用Python的find(默认子串正则匹配)。re.search