JSONYAMify

Home / Blog / JSON Schema

Apa itu JSON Schema dan Cara Memvalidasinya

Oleh Andi Putra Ogie · Update: Juni 2026 · 6 menit baca

JSON Schema adalah "blueprint" atau aturan yang mendefinisikan struktur, tipe data, dan batasan nilai yang valid untuk dokumen JSON. Dengan JSON Schema, tim bisa memastikan data yang masuk/keluar dari API selalu konsisten dengan kontrak yang disepakati.

Contoh Sederhana

Misal kita punya data user seperti ini:

{
  "nama": "Budi",
  "umur": 28,
  "email": "budi@example.com"
}

JSON Schema yang memvalidasi struktur di atas:

{
  "type": "object",
  "properties": {
    "nama": { "type": "string" },
    "umur": { "type": "integer", "minimum": 0 },
    "email": { "type": "string", "format": "email" }
  },
  "required": ["nama", "umur", "email"]
}

Kenapa JSON Schema Penting?

Tipe Validasi yang Umum Dipakai

💡 Sebelum menulis schema, pastikan dulu struktur data contohnya benar-benar valid dan rapi. Gunakan JSONYAMify untuk memformat dan memeriksa data contoh sebelum dijadikan basis schema.
🔧 Rapikan JSON Sebelum Membuat Schema

What is JSON Schema and How to Validate With It

By Andi Putra Ogie · Updated: June 2026 · 6 min read

JSON Schema is a "blueprint" — a set of rules that defines the structure, data types, and valid value constraints for a JSON document. With JSON Schema, teams can guarantee data flowing in and out of an API always matches an agreed-upon contract.

A Simple Example

Say we have this user data:

{
  "name": "John",
  "age": 28,
  "email": "john@example.com"
}

A JSON Schema that validates the structure above:

{
  "type": "object",
  "properties": {
    "name": { "type": "string" },
    "age": { "type": "integer", "minimum": 0 },
    "email": { "type": "string", "format": "email" }
  },
  "required": ["name", "age", "email"]
}

Why Does JSON Schema Matter?

Common Validation Keywords

💡 Before writing a schema, make sure your example data is actually valid and clean. Use JSONYAMify to format and inspect your sample data before basing a schema on it.
🔧 Clean Up JSON Before Building a Schema