コンテンツへスキップ
uencoder

JSON Schema を生成する方法

バリデーションとドキュメントのために、サンプルの JSON データから JSON Schema を推論します。

问题

JSON データがあり、バリデーションや API ドキュメントのために構造を記述するスキーマを生成したい。

前提条件

  • JSON の理解
  • JSON Schema の概念への習熟

ステップ

  1. 1. Analyze the sample JSON

    The generator inspects the JSON to determine types, required fields, array item types, and nested object structures. It infers the schema from the data. Multiple samples can improve accuracy by detecting optional fields and enum values.

    入力
    {"name":"Alice","age":30}
    输出
    inferred structure
  2. 2. Generate the schema

    Produce a JSON Schema document with type constraints for each field. Strings get type string, numbers get type number or integer, arrays get items with the element type, and objects get properties with nested schemas. Mark fields present in all samples as required.

    入力
    sample JSON
    输出
    JSON Schema draft 2020-12
  3. 3. Refine and validate

    Review the generated schema and refine it: add constraints (minLength, maximum, pattern), identify optional vs required fields, and set enum values for fields with known options. Validate the original JSON against the schema to confirm it passes.

    入力
    schema + original JSON
    输出
    validation passes

期待される結果

サンプルデータを検証でき、ランタイムバリデーションや API ドキュメントに利用できる JSON Schema。

よくあるエラー

Schema is too permissive
A single sample cannot infer all constraints. Add more samples or manually refine the schema with tighter constraints.
Array item type is wrong
If the array contains mixed types, the schema may infer a union type. Provide more samples or specify the expected item type manually.

トラブルシューティング指引

  • If validation fails against the generated schema, the schema may have over-constrained a field. Relax the constraint.
  • Use multiple samples to detect optional fields and enum values.

セキュリティ上の制限

  • Schema generation is a read-only analysis. No data is transmitted.

関連ツール

関連用語

参考链接