# JsonActionCli **Repository Path**: lu9944_admin/json-action-cli ## Basic Information - **Project Name**: JsonActionCli - **Description**: 用于给AI快速编辑json文本,内置skills - **Primary Language**: Unknown - **License**: Not specified - **Default Branch**: main - **Homepage**: None - **GVP Project**: No ## Statistics - **Stars**: 0 - **Forks**: 0 - **Created**: 2026-03-18 - **Last Updated**: 2026-03-18 ## Categories & Tags **Categories**: Uncategorized **Tags**: None ## README # i18n-cli > 简洁高效的 JSON 文件操作 CLI 工具,专为大型 i18n 文件设计 ## 特性 - 🚀 简洁命令:get / set / add / delete - 📍 点号路径:`common.save`、`items.0.name` - 🎯 智能输出:字符串直接输出,对象/数组 JSON 格式 - 💡 友好提示:错误时给出可执行的修复命令 - 📦 零依赖:单二进制文件,跨平台支持 ## 安装 ### 从源码编译 ```bash git clone https://github.com/xxx/i18n-cli.git cd i18n-cli cargo build --release ``` 编译后的二进制文件位于 `target/release/i18n-cli`。 ## 快速开始 ```bash # 获取值 i18n-cli get zh-CN.json common.save # 修改值 i18n-cli set zh-CN.json common.save "储存" # 新增值 i18n-cli add zh-CN.json newSection.key "新值" # 删除值 i18n-cli delete zh-CN.json common.testKey ``` ## 命令详解 ### get - 获取值 ```bash i18n-cli get ``` **示例:** ```bash i18n-cli get zh-CN.json common.save # → 保存 i18n-cli get zh-CN.json common # → {"save": "保存", ...} i18n-cli get zh-CN.json not.exist # → null i18n-cli get zh-CN.json items.0.name # → item1(支持数组索引) ``` **行为:** - 路径存在:输出值(字符串直接输出,对象/数组输出 JSON) - 路径不存在:输出 `null`,退出码 0 ### set - 修改值 ```bash i18n-cli set [--json] ``` **示例:** ```bash i18n-cli set zh-CN.json common.save "储存" i18n-cli set zh-CN.json version 2 i18n-cli set zh-CN.json enabled false i18n-cli set zh-CN.json items.0.name updated i18n-cli set zh-CN.json config --json '{"theme": "dark"}' ``` **行为:** - 父路径存在:修改值,退出码 0 - 父路径不存在:报错并提示使用 `add` 命令,退出码 1 ### add - 新增值 ```bash i18n-cli add [--json] ``` **示例:** ```bash i18n-cli add zh-CN.json newKey "新值" i18n-cli add zh-CN.json common.newKey "新值" i18n-cli add zh-CN.json newSection.deep.key "新值" # 自动创建中间路径 i18n-cli add zh-CN.json items.2.name item3 # 扩展数组 ``` **行为:** - 路径不存在:创建值(自动创建中间路径),退出码 0 - 路径已存在:报错并提示使用 `set` 命令,退出码 1 ### delete - 删除键 ```bash i18n-cli delete ``` **示例:** ```bash i18n-cli delete zh-CN.json common.save i18n-cli delete zh-CN.json items.0 # 删除数组元素 i18n-cli delete zh-CN.json not.exist # → null ``` **行为:** - 路径存在:删除键,退出码 0 - 路径不存在:输出 `null`,退出码 0 ## 路径语法 ### 基本语法 - 使用点号 `.` 分隔嵌套层级 - 示例:`common.save`、`settings.theme.dark` ### 数组索引 - 使用数字作为路径段访问数组 - 示例:`items.0.name` → `items[0].name` ### 无效路径格式 | 路径 | 错误原因 | |------|----------| | `""` | 空路径 | | `.` | 只有分隔符 | | `a..b` | 连续分隔符 | | `.a` | 以分隔符开头 | | `a.` | 以分隔符结尾 | ## 值类型 ### 自动识别类型 | 输入值 | JSON 结果 | 说明 | |--------|-----------|------| | `hello` | `"hello"` | 不带引号的字符串 | | `"hello"` | `"hello"` | 带引号的字符串 | | `"hello world"` | `"hello world"` | 含空格的字符串 | | `42` | `42` | 整数 | | `3.14` | `3.14` | 浮点数 | | `true` | `true` | 布尔 true | | `false` | `false` | 布尔 false | | `null` | `null` | null 值 | | `""` | `""` | 空字符串 | ### JSON 模式 使用 `--json` 标志直接传入 JSON: ```bash i18n-cli set file.json key --json '{"a": 1}' i18n-cli set file.json arr --json '[1, 2, 3]' ``` ## 在脚本中使用 ```bash # 获取值并存储到变量 VALUE=$(i18n-cli get zh-CN.json common.save) # 批量更新 i18n-cli set en.json common.save "Save" i18n-cli set zh-CN.json common.save "保存" # 检查退出码 if i18n-cli set config.json key value; then echo "更新成功" else echo "更新失败" fi ``` ## License MIT