JSON Formatter
A simple JSON formatting, validation, and conversion tool.
Features
- - Format/Beautify - Make JSON readable with proper indentation
- Compress/Minify - Remove whitespace for compact JSON
- Validate - Check JSON syntax and report errors
- Convert - JSON ↔ YAML conversion
Usage
CODEBLOCK0
Actions
| Action | Description |
|---|
| INLINECODE0 | Format JSON with indentation |
| INLINECODE1 |
Minify JSON (remove whitespace) |
|
validate | Validate JSON syntax |
|
to-yaml | Convert JSON to YAML |
|
from-yaml | Convert YAML to JSON |
Options
| Option | Type | Default | Description |
|---|
| INLINECODE5 | string | - | Input string or file path |
| INLINECODE6 |
int | 2 | Indentation spaces (for format) |
|
--file | bool | false | Treat input as file path |
Examples
CODEBLOCK1
Use Cases
- 1. Debug API responses - Format and inspect JSON data
- Reduce file size - Compress JSON for storage/transmission
- Validate config files - Check JSON syntax before deployment
- Convert formats - Switch between JSON and YAML for different tools
Current Status
In development.
JSON 格式化工具
一个简单的 JSON 格式化、验证和转换工具。
功能特性
- - 格式化/美化 - 通过适当缩进使 JSON 可读
- 压缩/精简 - 移除空白字符以生成紧凑的 JSON
- 验证 - 检查 JSON 语法并报告错误
- 转换 - JSON ↔ YAML 相互转换
使用方法
bash
python3 skills/json-formatter/scripts/json_formatter.py <操作> [选项]
操作说明
| 操作 | 描述 |
|---|
| format | 带缩进格式化 JSON |
| compress |
压缩 JSON(移除空白字符) |
| validate | 验证 JSON 语法 |
| to-yaml | 将 JSON 转换为 YAML |
| from-yaml | 将 YAML 转换为 JSON |
选项参数
| 选项 | 类型 | 默认值 | 描述 |
|---|
| --input | 字符串 | - | 输入字符串或文件路径 |
| --indent |
整数 | 2 | 缩进空格数(用于格式化) |
| --file | 布尔值 | false | 将输入视为文件路径 |
示例
bash
格式化 JSON
python3 skills/json-formatter/scripts/json_formatter.py format --input {name:test,value:123}
压缩 JSON
python3 skills/json-formatter/scripts/json_formatter.py compress --input {name: test, value: 123}
验证 JSON
python3 skills/json-formatter/scripts/json_formatter.py validate --input {name:test}
转换为 YAML
python3 skills/json-formatter/scripts/json_formatter.py to-yaml --input {name:test,items:[1,2,3]}
从 YAML 转换为 JSON
python3 skills/json-formatter/scripts/json_formatter.py from-yaml --input name: test
使用场景
- 1. 调试 API 响应 - 格式化并检查 JSON 数据
- 减小文件大小 - 压缩 JSON 以便存储/传输
- 验证配置文件 - 在部署前检查 JSON 语法
- 格式转换 - 在不同工具间切换 JSON 和 YAML
当前状态
开发中。