Index of every page on this site: llms.txt
All skills
steelan9199 avatar

/format-json

@9e01957
Run it yourself

将 Markdown 代码块中未格式化的 JSON 格式化为标准的美化 JSON。何时使用:当用户需要美化 .md 文件中的 JSON 数据或要求格式化 JSON 代码块时。

  • 2 files
  • 4.2 KB
  • Updated 5 months ago
  • GitHub
Use this Skill: https://skilld.dev/gh/steelan9199/wechat-publisher/format-json

Nothing lands on disk. Nothing to clean up.

Fork this Skill

Edit a local copy. It keeps the author and licence.

SKILL.md

≈50 tokens for metadata: the name and description. ≈705 when used: this file.

Description uses 1.3% of example budget

Before choosing a Skill, your Agent reads its name and description. All available Skills share that space.

  • A shorter description leaves more room for other Skills. This entry exceeds our 1% size suggestion.

In our Claude Code example, all Skill names and descriptions share 8,000 characters. This Skill uses ≈101 characters, or 1.3%.

The 1% threshold is a size suggestion. Longer descriptions can still fit.

Your model, settings, and other Skills decide how much text your Agent can read.

Example settings and source

The example uses a 200k-token context and default Claude Code settings. The count includes the name, description, separators, and when_to_use when present. Codex also counts local file paths.

Skit's source and limits: Codex 0.160.1, Claude Code 2.1.292.

Format JSON in Markdown

功能概述

本 Skill 用于扫描 Markdown 文件中的代码块,自动将其中未格式化(压缩成一行)的 JSON 数据转换为标准缩进格式(2 空格),使其易于人类阅读。支持 ```、```json 等任意语言标识的代码块;只要代码块内容能被 JSON.parse() 成功解析,就会自动美化,解析失败则保持原样不变。

环境说明

  • 本 Skill 的脚本 format-json.js 与 SKILL.md 位于同一目录。
  • 下文以 <skill-dir> 指代该目录(即 skill 的安装目录)。

执行步骤

步骤 动作 命令/操作
1 获取目标文件 确定用户指定的 .md 文件路径;如未指定,询问用户
2 运行格式化脚本 执行 node <skill-dir>/format-json.js <文件路径>
3 确认执行结果 检查控制台是否输出 "JSON 格式化完成"
4 向用户反馈 报告格式化完成,并展示变更后的 JSON 代码块

决策逻辑

条件 执行动作
用户指定了 .md 文件路径 直接运行脚本
用户未指定文件路径 询问用户需要格式化的 .md 文件路径
脚本执行失败 按【脚本说明】手动执行格式化步骤

脚本说明

本 skill 目录下附带脚本 format-json.js,逻辑如下:

  1. 读取目标 .md 文件内容。
  2. 正则匹配所有代码块:(```(?:\w+)?\n)([\s\S]*?)(\n```)。
  3. 对每个代码块内容执行 trim(),去除前后空白字符(包括空行)。
  4. 尝试 JSON.parse() 解析。
    • 成功:替换为 JSON.stringify(parsed, null, 2)。
    • 失败:保留原样。
  5. 将结果写回原文件。

错误处理

错误场景 处理方式
文件不存在 检查路径是否正确,提示用户提供正确的 .md 文件路径
脚本执行失败 检查 Node.js 环境;如环境问题则按【脚本说明】手动执行
未找到可格式化的 JSON 向用户说明文件中不存在可被 JSON.parse() 解析的代码块

示例

Before

```json
{ "users": [{ "name": "Alice", "age": 30 }], "count": 1 }
```

After

```json
{
  "users": [
    {
      "name": "Alice",
      "age": 30
    }
  ],
  "count": 1
}
```

Source: SKILL.md on GitHub

skilld matched fixed text patterns in SKILL.md and file names. Patterns miss obfuscated code.

skilld run checks every file with the same patterns. It asks for approval before it loads a Skill with a behavior marked Needs approval.

No third-party reports yet.

Signed by skilld at 9e01957. This ties the file your Agent reads to that commit on GitHub. It does not review the instructions.

Last checked against GitHub 3 weeks ago.

Activeupdated 5 months ago

README badge

README badge for steelan9199/wechat-publisher/format-json