Skip to content
cosmodev ~/tools/json-to-schema

مولد JSON Schema از JSON

Data & DevOps

از هر سند JSON یک JSON Schema نسخهٔ draft-07 استخراج کنید: انواع اسکالر، ادغام آیتم‌های آرایه، آبجکت‌های همه‌کلید الزامی و حالت سخت‌گیرانهٔ اختیاری. به‌صورت محلی در مرورگر شما اجرا می‌شود، همراه با لینک قابل اشتراک.

امتحان کنید::
اشیای سخت‌گیرانه

اشیای سخت‌گیرانه "additionalProperties": false را به اسکیمای هر شیء اضافه می‌کنند.

(مستندات به انگلیسی)

What it does

Reads one JSON document and infers the JSON Schema (draft-07) that describes it. Scalars become their exact types — with integers split from fractional numbers — objects list every key as required, and arrays merge their elements into one items schema. A mixed array like [1, "a"] produces a sorted type list (["integer", "string"]), and an empty array stays schema-free. Turn on Strict objects to add "additionalProperties": false to every object, closing the schema against extra keys. Everything runs locally in your browser.

How to use it

  1. Paste JSON into JSON document (left), or tap a chip — Object, Mixed array, or Nested — to see each inference case. Sample loads a nested user document; Clear empties the box.
  2. The schema appears live in JSON Schema (draft-07) (right). Key order is sorted alphabetically, so the same document always yields the same schema.
  3. Flip Strict objects on or off and the output updates instantly.
  4. Copy takes the schema; Download saves it as schema.json.
  5. Copy share link encodes your input and the strict setting in the URL.

Examples

A small object:

{"id": 1, "name": "widget", "price": 9.99} → an object schema with id as integer, name as string, price as number — 9.99 is fractional, so it is number, not integer.

Mixed array:

[1, "a", null, 2.5] → { "type": "array", "items": { "type": ["integer", "null", "number", "string"] } }

Integral floats count as integers — JSON has no separate int type, so 2.0 infers as integer.

How schema inference works

Inference walks the document once and never guesses beyond what is present:

Input Inferred type
42, 2.0 integer
3.14 number
true boolean
null null
"hi" string
[] array (no items)
[1, 2] array with items: {"type": "integer"}
{"a": 1} object, required: ["a"]

Arrays describe shape, not constraints: when elements disagree, the differing keywords are dropped and only the sorted type union survives. The schema is a starting point — tighten required, add formats and bounds by hand where your API demands them.

کد منبع14 زبان

100% سمت کاربر · داده‌های شما هرگز از مرورگرتان خارج نمی‌شود. به کارتان آمد؟ آن را با یک همکار به اشتراک بگذارید.