360 Secure SkillHub
360 安全技能中心

JSON修复工具

这是一款Node.js命令行工具,核心修复 trailing commas、单引号、无引号键等常见JSON语法问题,还支持移除注释、转换十六进制数。适用于手动编辑的配置文件、有语法问题的JSON数据文件。支持单文件修复(可指定输出)、目录递归批量修复;默认创建.bak备份,采用沙箱解析确保安全,修复后验证JSON有效性。

wanng-ide
wanng-ide
热度 19.41
最近更新 2026-09-22 02:57:12
分类:效率依赖:代码执行 / 读写文件应用场景:文件转换

安装技能

复制下面的话术发给你的 Agent,它会通过 secure-skills 检索并安装该技能。

执行命令安装此 skill: npx secure-skills-cli add json-repair-kit
Metadata
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 Node eval may strip them if they are line comments outside of strings).
  • Hex/Octal Numbers: 0xFF -> 255

Safety

  • Backup: Always creates a .bak file before overwriting (unless --no-backup is used, but default is safe).
  • Validation: Verifies the repaired content is valid JSON before writing.
  • Eval Sandbox: Uses vm.runInNewContext to parse, ensuring no access to global scope or process. It is safer than eval().