サンプル JSON から JSON Schema を自動作成・検証

JSON Schema from samples: infer draft 2020-12 and validate data

手元の JSON / JSON Lines のサンプルから JSON Schema(draft 2020-12)を推定し、必須項目・選択肢・日時やメールの形式まで判定。内蔵の簡易バリデーターでデータも検証できます。

ClaudeHermes AgentCodexCursorMIT(改変・再配布・商用利用可)Python

できること

API のレスポンスや設定ファイル、データのエクスポートなど、仕様書のない JSON から「たたき台」になるスキーマを作り、データが形に合っているかを確かめます。

  • 全サンプルを通して型・null 許容・必須/任意・配列の中身の型を判定(例: 45件中23件にしかない項目は任意)
  • 値の種類が少ない文字列は enum に、すべての値が同じ形式なら date-time date time email uuid ipv4 ipv6 uri の format を付与
  • 型が混ざっている項目や任意項目をメモとして表示し、作ったスキーマで全サンプルが通るか自動で確認
  • 内蔵バリデーターで別のデータを検証し、ファイル:行 /JSONポインタ: 理由 の形でエラーを表示
  • 観測した最小/最大値を付ける --bounds、余分な項目を禁止する --strict も選べます

使い方

python scripts/json_schema_tool.py infer samples/*.json --out schema.json --title Order
python scripts/json_schema_tool.py validate --schema schema.json new-batch.jsonl

Claude・Codex・Hermes Agent・Cursor に「この JSON のスキーマを作って」と頼むと、推定したあと必須項目や enum が妥当かをあなたと確認しながら仕上げます。

必要な環境

  • Python 3.10 以上(標準ライブラリのみ)

注意点

  • 推定は見たサンプルだけが根拠です。サンプルが少ないと、本当は任意の項目が必須に見えたり、偶然の値が enum になったりします。
  • 内蔵バリデーターは主要なキーワードのみ対応です(if/then/else や unevaluatedProperties、外部の $ref などは未対応で、その旨を表示します)。厳密な検証が必要なら専用ライブラリを使ってください。
  • データは外部に送信しません。enum に実データの値が入ることがあるので、公開前に確認してください。
English description

Infer a draft 2020-12 JSON Schema from sample JSON or JSON Lines, with required fields, enums and formats, and validate data with a built-in minimal validator.

What it does

Turn undocumented JSON (API responses, configs, exports) into a draft schema and check that data matches it.

  • Merges every sample to determine types, nullability, required vs optional properties and array item types (for example, a field present in 23 of 45 objects is optional)
  • Emits enums for strings with few distinct values, and formats (date-time, date, time, email, uuid, ipv4, ipv6, uri) only when every value matches
  • Notes optional and mixed-type fields, and self-checks that all samples validate against the inferred schema
  • Validates other data with a built-in validator and prints errors as file:line /json/pointer: reason
  • Optional --bounds (observed min/max) and --strict (no additional properties)

How to use

python scripts/json_schema_tool.py infer samples/*.json --out schema.json --title Order
python scripts/json_schema_tool.py validate --schema schema.json new-batch.jsonl

Ask Claude, Codex, Hermes Agent or Cursor to "write a JSON Schema for this data"; it infers the schema, then reviews required fields and enums with you before finalizing.

Requirements

  • Python 3.10+ (standard library only)

Caveats

  • Inference only knows the samples it saw: with few samples, optional fields can look required and coincidental values can become enums.
  • The built-in validator covers the common keywords only (if/then/else, unevaluatedProperties, remote $ref and others are not checked, and it says so). Use a full validator library when strict compliance matters.
  • Data never leaves your machine. Enums may contain real values, so review them before publishing a schema.

インストール方法

  1. ダウンロードしたZIPを展開します(中に json-schema-from-samples/ フォルダと SKILL.md があります)。
  2. フォルダごと、使うエージェントのスキル置き場にコピーします。
    • Claude:~/.claude/skills/(プロジェクト単位なら .claude/skills/)
    • Hermes Agent:~/.hermes/skills/
    • Codex:~/.agents/skills//Cursor:~/.cursor/skills/
    • Claude アプリ(claude.ai):「カスタマイズ → スキル」からZIPをアップロード
  3. エージェントを再起動し、スキル一覧に表示されることを確認します。

Windows・Mac 別、エージェント別のインストール手順

出品者

AI Skill Market 公式

出品スキル 44 件

出品者のプロフィールとスキル一覧