← 返回 Skills 市场
kikikari

JSON Utils

作者 KikiKari · GitHub ↗ · v1.0.0 · MIT-0
cross-platform ✓ 安全检测通过
73
总下载
0
收藏
1
当前安装
1
版本数
在 OpenClaw 中安装
/install json-utils
功能描述
Robust JSON parsing and validation with Pydantic schemas, JSON Schema validation, batch processing, and automatic JSON repair for LLM outputs. Use when Codex...
使用说明 (SKILL.md)

JSON Utils

Robuste JSON-Verarbeitung mit Pydantic-Validierung, JSON Schema Support und automatischer JSON-Reparatur.

Erweiterte Nutzung

Für WebSearch-Integration und Multi-Environment JSON-Verarbeitung siehe:

  • ../scripting-utils/ - Kombiniert JSON-Utils mit WebSearch für API-Dokumentation und Response-Validierung

Module

Installation

pip install pydantic json-repair jsonschema

Module

Script Zweck
json_processor.py Kern-Funktionen: Parsing, Validierung, Tool-Calls
json_schema_validator.py JSON Schema Draft 7/2020-12 Validierung
json_batch_processor.py Batch-Verarbeitung & JSON-Lines (NDJSON)
validate_tool_output.py CLI für Tool-Output Validierung

Quick Start

from json_processor import parse_json, parse_and_validate, validate_tool_call
from pydantic import BaseModel

# Einfaches Parsing mit Auto-Reparatur
result = parse_json('{"name": "test", "value": 123,}')  # trailing comma OK

# Mit Pydantic-Validierung
class ToolCall(BaseModel):
    tool: str
    arguments: dict = {}

llm_output = '{"tool": "search", "arguments": {"q": "hello"},}'
validated = parse_and_validate(llm_output, ToolCall)

Integration mit scripting-utils

# Für erweiterte JSON-Verarbeitung mit WebSearch:
from scripting_utils.json_websearch import WebSearchJSON

# Sucht API-Doku, validiert Responses, generiert Schemas
ws = WebSearchJSON()
result = ws.search_and_validate(
    query="github api repos endpoint",
    schema_path="github_schema.json"
)

Siehe ../scripting-utils/scripts/json_websearch.py für:

  • API-Dokumentation via WebSearch
  • Auto-Generierung von JSON-Schemas
  • Batch-Validierung von API-Endpoints
  • Cross-Platform JSON-Verarbeitung

Szenarien

1. LLM-Output verarbeiten

from json_processor import parse_json

# Verschiedene Input-Formate
parse_json('{"valid": true}')                              # Direkt OK
parse_json('```json\
{"valid": true}\
```')                # Aus Code-Block extrahiert
parse_json('{"valid": true,}')                             # Trailing comma repariert
parse_json('Some text {"tool": "x"} more text')           # JSON aus Text extrahiert

2. JSON Schema Validierung

from json_schema_validator import validate_with_jsonschema, SchemaBuilder

# Gegen Datei validieren
validate_with_jsonschema(data, "/path/to/schema.json")

# Dynamisches Schema erstellen
schema = SchemaBuilder.object(
    properties={
        "name": SchemaBuilder.string(min_length=1),
        "age": SchemaBuilder.integer(minimum=0),
        "tags": SchemaBuilder.array(SchemaBuilder.string())
    },
    required=["name"]
)

3. Batch-Verarbeitung

from json_batch_processor import process_file_batch, process_jsonl_file
from pathlib import Path

# Mehrere JSON-Dateien parallel
results = process_file_batch(
    [Path("a.json"), Path("b.json"), Path("c.json")],
    repair=True,
    max_workers=4
)

# JSON-Lines (NDJSON) verarbeiten
results = process_jsonl_file(Path("data.jsonl"))

for result in results:
    if result.success:
        print(f"[{result.source}] OK: {result.data}")
    else:
        print(f"[{result.source}] ERROR: {result.error}")

4. JSON-Lines verarbeiten

# Konvertiere JSON-Array zu JSON-Lines
python json_batch_processor.py data/*.json --output output.jsonl

# JSON-Lines validieren
python json_batch_processor.py data.jsonl --jsonl --repair

5. Tool-Call validieren

from json_processor import validate_tool_call

result = validate_tool_call('{"tool": "weather", "arguments": {"city": "Berlin"}}')
# Mit Tool-Namensprüfung
try:
    result = validate_tool_call(raw_json, tool_name="weather")
except JSONValidationError:
    pass  # Falscher Tool-Name

CLI-Nutzung

Einzelnes JSON:

# Datei parsen
python scripts/json_processor.py -f output.json --pretty

# String parsen mit Reparatur
python scripts/json_processor.py '{"test": 123,}' --repair --pretty

JSON Schema Validierung:

python scripts/json_schema_validator.py input.json -s schema.json

Batch-Verarbeitung:

# Mehrere Dateien
python scripts/json_batch_processor.py *.json --workers 8

# JSON-Lines
python scripts/json_batch_processor.py data.jsonl --jsonl --output results.jsonl

# Nur Summary
python scripts/json_batch_processor.py *.json --summary

API-Dokumentation

Siehe references/api_reference.md für vollständige API-Dokumentation.

Exception-Hierarchie

JSONProcessingError (Base)
├── JSONValidationError (Pydantic/Schema-Fehler)
│   └── SchemaValidationError (JSON Schema spezifisch)
└── JSONRepairError (Reparatur nicht möglich)

Häufige Fehler repariert

  • ✅ Trailing commas: {"a": 1,}{"a": 1}
  • ✅ Markdown-Blocks: \``json
    {}
    ```{}`
  • ✅ JavaScript-Kommentare: {"a": 1} // comment{"a": 1}
  • ✅ Unescaped newlines in Strings
  • ✅ Einzelne statt doppelte Anführungszeichen
安全使用建议
This package appears to do exactly what it says: robust JSON parsing, repair, Pydantic and JSON Schema validation, and batch/JSONL processing. Before installing or running it: (1) install the documented Python dependencies from trusted sources (pip install pydantic json-repair jsonschema); (2) be aware the CLI and batch functions read and may write local files — only run it against files you trust; (3) the docs reference an external '../scripting-utils' integration that is not included—do not blindly follow instructions that require sibling directories you don't have; (4) when using dynamic model/schema-based validation, double-check schema files you pass in (they are loaded from disk and control what is accepted); and (5) if you allow an autonomous agent to call this skill, note that it can read local files you give it as arguments, so restrict inputs accordingly.
功能分析
Type: OpenClaw Skill Name: json-utils Version: 1.0.0 The json-utils skill bundle provides a set of robust utilities for parsing, repairing, and validating JSON data, particularly tailored for LLM outputs. It utilizes standard libraries such as Pydantic, json-repair, and jsonschema to handle common formatting errors (like trailing commas or markdown blocks) and enforce data schemas. The code in scripts like json_processor.py and json_batch_processor.py is well-structured, follows best practices for utility scripts, and contains no indicators of malicious intent, data exfiltration, or unauthorized execution.
能力评估
Purpose & Capability
Name and description match the provided scripts: parsing, repair, Pydantic validation, JSON Schema validation, batch/JSONL processing and a CLI. Declared requirements are minimal (none), and the SKILL.md correctly documents required Python packages (pydantic, json-repair, jsonschema) used by the code.
Instruction Scope
SKILL.md and the scripts confine actions to JSON parsing/validation and reading/writing local files. A minor note: the docs reference an external sibling 'scripting-utils' integration (../scripting-utils/json_websearch.py) which is not part of this package; that is a use-case hint but could lead callers to attempt reading sibling paths that don't exist in the skill bundle.
Install Mechanism
There is no automated install spec (instruction-only style), and the SKILL.md suggests pip installing common packages from PyPI. No downloads from arbitrary URLs or archive extraction appear in the manifest or scripts.
Credentials
The skill requests no environment variables, no credentials, and does not read configuration paths beyond files supplied by the user. All named imports (pydantic, json_repair, jsonschema) are consistent with the documented functionality.
Persistence & Privilege
always is false and the skill does not attempt to modify agent configuration or other skills. It runs as standard CLI/Python modules and exits normally; autonomous invocation is enabled by default (platform standard) but the skill's actions are limited to local parsing and file I/O.
如何使用
  1. 确保已安装 OpenClaw(本地或 Docker 部署)
  2. 在对话框中输入安装命令:/install json-utils
  3. 安装完成后,直接呼叫该 Skill 的名称或使用 /json-utils 触发
  4. 根据 Skill 的参数说明提供必要输入,即可获得结构化输出
版本历史
v1.0.0
Initial release of json-utils: Robust JSON parsing, validation, and repair for LLM and batch workflows. - Parses and auto-repairs common JSON errors (trailing commas, markdown blocks, unescaped newlines, comments). - Validates JSON against Pydantic models and JSON Schemas (Draft 7/2020-12). - Batch processing for multiple JSON files and NDJSON (JSON-Lines) with parallelization. - Extracts JSON from mixed text (e.g., LLM outputs). - CLI tools for parsing, validation, and batch processing. - Integration tips for scripting-utils and API documentation included.
元数据
Slug json-utils
版本 1.0.0
许可证 MIT-0
累计安装 1
当前安装数 1
历史版本数 1
常见问题

JSON Utils 是什么?

Robust JSON parsing and validation with Pydantic schemas, JSON Schema validation, batch processing, and automatic JSON repair for LLM outputs. Use when Codex... 它是一个面向 Claude Code / OpenClaw 的 AI Agent Skill 插件,目前累计下载 73 次。

如何安装 JSON Utils?

在 OpenClaw 或 Claude Code 对话框中运行命令「/install json-utils」即可一键安装,无需额外配置。

JSON Utils 是免费的吗?

是的,JSON Utils 完全免费,采用 MIT-0 许可证,可自由下载、安装和使用。

JSON Utils 支持哪些平台?

JSON Utils 跨平台运行,可在任意部署了 OpenClaw / Claude Code 的环境中使用(cross-platform)。

谁开发了 JSON Utils?

由 KikiKari(@kikikari)开发并维护,当前版本 v1.0.0。

💬 留言讨论