JSON 修复工具包:自动修复格式错误的 JSON - Openclaw Skills
作者:互联网
2026-03-30
什么是 json-repair-kit?
JSON 修复工具包是 Openclaw Skills 生态系统中的一个强大工具,它简化了修复“松散”JSON 文件的过程。开发人员经常遇到带有尾随逗号、单引号或未加引号的键的 JSON 文件,这些错误通常会破坏严格的解析器。此工具利用安全的 Node.js 环境将这些格式错误的结构评估为 JavaScript 对象,并将它们重新序列化为格式完美、有效的 JSON。
通过将此工具集成到您的本地开发环境中,您可以确保配置文件、手动编辑的数据和遗留导出与现代应用程序保持兼容。作为 Openclaw Skills 库的一部分,它致力于为数据清理和工作流自动化提供开发人员友好的界面。
下载入口:https://github.com/openclaw/skills/tree/main/skills/wanng-ide/json-repair-kit
安装与下载
1. ClawHub CLI
从源直接安装技能的最快方式。
npx clawhub@latest install json-repair-kit
2. 手动安装
将技能文件夹复制到以下位置之一
全局模式~/.openclaw/skills/
工作区
/skills/
优先级:工作区 > 本地 > 内置
3. 提示词安装
将此提示词复制到 OpenClaw 即可自动安装。
请帮我使用 Clawhub 安装 json-repair-kit。如果尚未安装 Clawhub,请先安装(npm i -g clawhub)。
json-repair-kit 应用场景
- 清理手动编辑后带有尾随逗号的配置文件。
- 将带有单引号的 JavaScript 风格对象转换为严格的 JSON 格式。
- 修复包含未加引号的键或非标准数字格式(如十六进制或八进制)的数据导出。
- 批量修复整个目录结构中的嵌套 JSON 文件。
- 从类 JSON 文件中删除注释,使其与严格环境兼容。
- 该工具通过命令行参数接受目标文件或目录路径。
- 它将格式错误的文件内容读取到内存中。
- 原始字符串在安全的 vm.runInNewContext 沙箱中进行评估,以安全地将松散语法转换为标准的 JavaScript 对象。
- 验证步骤在进行任何写入操作之前确保生成的对象结构是合理的。
- 该工具创建一个 .bak 备份文件以保留原始数据的完整性。
- 最后,清理后的对象被字符串化并作为有效的 JSON 写回磁盘。
json-repair-kit 配置指南
要使用 Openclaw Skills 集合中的此组件,请确保您已配置 Node.js 环境。运行以下命令来修复您的文件:
# 原地修复特定文件(自动创建 .bak 备份)
node skills/json-repair-kit/index.js --file path/to/broken.json
# 修复文件并将输出保存到特定位置
node skills/json-repair-kit/index.js --file broken.json --out fixed.json
# 递归扫描并修复目录中的所有 JSON 文件
node skills/json-repair-kit/index.js --dir config/ --recursive
json-repair-kit 数据架构与分类体系
JSON 修复工具包处理基于文本的数据文件并生成标准化输出。它根据以下架构组织文件操作:
| 属性 | 描述 | 输出格式 |
|---|---|---|
| 源文件 | 格式错误的 JSON 或 .txt 文件 | 松散的 JS 对象表示法 |
| 修复后的文件 | 清理后的有效 JSON 输出 | 严格的 RFC 8259 JSON |
| 备份文件 | 原始源文件的 .bak 副本 | 原始内容 |
它处理的数据类型包括字符串、布尔值、数组、嵌套对象以及数值转换(十六进制/八进制转十进制)。
name: json-repair-kit
description: Repair malformed JSON files by normalizing them through Node.js evaluation. Use this to fix trailing commas, single quotes, unquoted keys, or other common syntax errors in JSON files (e.g. config files, manually edited data).
JSON Repair Kit
A utility to repair broken or "loose" JSON files (like those with trailing commas, single quotes, or unquoted keys) by parsing them as JavaScript objects and re-serializing as valid JSON.
Usage
# Repair a file in place (creates .bak backup)
node skills/json-repair-kit/index.js --file path/to/broken.json
# Repair and save to a new file
node skills/json-repair-kit/index.js --file broken.json --out fixed.json
# Scan directory and repair all .json files (recursive)
node skills/json-repair-kit/index.js --dir config/ --recursive
Supported Repairs
- Trailing Commas:
{"a": 1,}->{"a": 1} - Single Quotes:
{'a': 'b'}->{"a": "b"} - Unquoted Keys:
{key: "value"}->{"key": "value"} - Comments: Removes JS-style comments
//(if parser supports it, standard Nodeevalmay strip them if they are line comments outside of strings). - Hex/Octal Numbers:
0xFF->255
Safety
- Backup: Always creates a
.bakfile before overwriting (unless--no-backupis used, but default is safe). - Validation: Verifies the repaired content is valid JSON before writing.
- Eval Sandbox: Uses
vm.runInNewContextto parse, ensuring no access to global scope or process. It is safer thaneval().
相关推荐
专题
+ 收藏
+ 收藏
+ 收藏
+ 收藏
+ 收藏
最新数据
相关文章
慕尼黑 MVG & S-Bahn 实时追踪命令行工具 - Openclaw Skills
Reddit 研究技能:自动化社群洞察 - Openclaw Skills
豆包聊天:带有联网搜索功能的免费 AI 对话 - Openclaw Skills
NightPatch:自动化工作流优化 - Openclaw 技能
国产 AI 视频生成器:Wan2.6 与可灵集成 - Openclaw Skills
Sonos Announce:智能音频状态恢复 - Openclaw Skills
Hypha Payment:P2P 代理协作与 USDT 结算 - Openclaw Skills
Cashu Emoji:隐藏代币编解码 - Openclaw Skills
技术 SEO 精通:审计、修复与监控 - Openclaw Skills
Teamo Strategy:高级认知任务拆解 - Openclaw Skills
AI精选
