✓{}

Basic JSON Schema Validator

Validate JSON against common schema rules directly in the browser

Basic JSON Schema Validator — what it does

Validate a JSON document against a schema covering the common rules: required fields, types, and the basic constraints most schemas actually use. It answers whether a payload matches the contract, which is a different and more useful question than whether it merely parses.

Worked example

An order payload checked against a schema that uses required, type, pattern, minLength, minimum/maximum and items, which are the keywords this validator implements.

Input — the schema, then the JSON document

{"type":"object","required":["id","email","qty"],
 "properties":{"id":{"type":"string","pattern":"^ORD-\\d{4}$"},
  "email":{"type":"string","minLength":5},
  "qty":{"type":"number","minimum":1,"maximum":100},
  "tags":{"type":"array","items":{"type":"string"}}}}

{"id":"ORD-10421","email":"ann.lee@example.com","qty":0,"tags":["rush",7]}

Output — status 3 Validation errors

$.id: does not match pattern
$.qty: below minimum 1
$.tags[1]: expected string, got number

Paths start at $ and use [index] for array items. A document that passes prints Valid ✓.

When this tool helps

  • Checking that an API payload matches the documented contract before sending it.
  • Validating a configuration file against the schema a tool publishes.
  • Testing that your own schema accepts and rejects the examples you expect.

How to use it

  1. Paste the JSON Schema.
  2. Paste the JSON document to check.
  3. Run the validation.
  4. Read which rules passed and which failed.

Accuracy, limits, and good practice

  • Start with required and type — those two catch the overwhelming majority of real integration failures.
  • Test the negative cases too: a schema that accepts everything you throw at it is usually not constraining anything.
  • This covers common rules rather than the full specification; complex schemas with conditionals and references need a full validator library.
  • Keep the schema in version control beside the code that produces the payload; a schema that drifts from reality is worse than no schema.

Frequently asked questions

What is JSON Schema for?

Describing the shape a document must have, so producers and consumers can agree on structure and validate automatically.

Does valid JSON mean valid against a schema?

No. Parsing proves syntax; schema validation proves the structure and types match what was agreed.

Which draft is supported?

The common keywords shared across drafts are handled. Draft-specific advanced features may not be evaluated.

Where do I get a schema?

Many APIs and tools publish one. Otherwise write a minimal schema covering required fields and types, and grow it as you learn the data.

How are "integer" and type lists checked?

"type": "integer" accepts whole numbers only: 3 passes and 3.5 is reported as "expected integer, got number". A list such as ["string", "null"] passes if any entry matches, so null is accepted and 42 is reported as "expected string | null, got number".

Which keywords are silently ignored?

Everything outside the implemented set: enum, const, additionalProperties, format, uniqueItems, minItems, allOf/anyOf/oneOf, $ref and conditionals are not checked, so a document can be reported valid while breaking them. In a test, a schema with enum and additionalProperties: false accepted "status": "pending" and an extra property without comment.

Related tools on this site

Everything above runs inside this page. Basic JSON Schema Validator needs no account, no upload, and no server round trip — close the tab and nothing is left behind.

基礎 JSON Schema 驗證器能做什麼

依 Schema 驗證 JSON 文件,涵蓋常用規則:必填欄位、型別,以及多數 Schema 實際會用到的基本限制。它回答的是「載荷符不符合約定」,這與「它解析得過嗎」是不同、也更有用的問題。

實際範例

一筆訂單資料對照一份採 required、type、pattern、minLength、minimum/maximum 與 items 的 schema 來驗證,這些正是此驗證器實作的關鍵字。

原文:先是 schema,再來是 JSON 文件

{"type":"object","required":["id","email","qty"],
 "properties":{"id":{"type":"string","pattern":"^ORD-\\d{4}$"},
  "email":{"type":"string","minLength":5},
  "qty":{"type":"number","minimum":1,"maximum":100},
  "tags":{"type":"array","items":{"type":"string"}}}}

{"id":"ORD-10421","email":"ann.lee@example.com","qty":0,"tags":["rush",7]}

驗證訊息:狀態 3 Validation errors

$.id: does not match pattern
$.qty: below minimum 1
$.tags[1]: expected string, got number

路徑從 $ 開始,陣列元素以 [索引] 表示。通過驗證的文件會顯示 Valid ✓。

什麼時候用得上

  • 送出前確認 API 載荷符合文件所述的約定。
  • 依工具公布的 Schema 驗證設定檔。
  • 測試自己寫的 Schema 是否如預期地接受與拒絕範例。

使用步驟

  1. 貼上 JSON Schema。
  2. 貼上要檢查的 JSON 文件。
  3. 執行驗證。
  4. 查看哪些規則通過、哪些失敗。

精確度、限制與實務建議

  • 先從必填與型別下手——這兩項就能攔下絕大多數真實的介接失敗。
  • 也要測反例:一個什麼都接受的 Schema,通常等於什麼都沒約束。
  • 本工具涵蓋常用規則而非完整規格;含條件式與參照的複雜 Schema 需要完整的驗證函式庫。
  • 請把 Schema 放進版本控制,與產生載荷的程式放在一起;與現實脫節的 Schema 比沒有 Schema 更糟。

常見問題

JSON Schema 是做什麼的?

描述文件必須具備的形狀,讓產生端與使用端對結構取得共識並自動驗證。

JSON 有效就等於通過 Schema 嗎?

不等於。解析成功只證明語法;Schema 驗證才證明結構與型別符合約定。

支援哪個 draft?

各 draft 共通的常用關鍵字都有處理;特定 draft 的進階功能可能不會被評估。

Schema 從哪裡取得?

許多 API 與工具都有公布。否則請先寫一份只涵蓋必填欄位與型別的最小 Schema,再隨著理解逐步擴充。

"integer" 與型別陣列怎麼檢核?

"type": "integer" 只接受整數:3 通過,3.5 會回報「expected integer, got number」。像 ["string", "null"] 這樣的陣列,只要符合其中一個就通過,所以 null 可以,42 會回報「expected string | null, got number」。

哪些關鍵字會被默默略過?

實作範圍以外的全部:enum、const、additionalProperties、format、uniqueItems、minItems、allOf/anyOf/oneOf、$ref 與條件式都不會檢核,因此文件違反了這些規則仍可能被回報為有效。測試時,一份含 enum 與 additionalProperties: false 的 schema 就直接接受了 "status": "pending" 和多餘的屬性。

本站相關工具

以上步驟全部在這個頁面內完成,基礎 JSON Schema 驗證器 不需要註冊、不上傳檔案、也不經過伺服器,關閉分頁後不會留下任何資料。