Search tools...
Developer Tools

JSON Schema Generator — सम्पूर्ण गाइड

JSON Schema generate गर्नुहोस्, validate गर्नुहोस् र APIs मा integrate गर्नुहोस्

१६ मिनेटUpdated March 19, 2026JSON, schema, validation, API, TypeScript, developer-tools

Modern APIs, configuration files, databases — सबै JSON प्रयोग गर्छन्। तर raw JSON schema-less हुन्छ — कुनै पनि key ले कुनै पनि value hold गर्न सक्छ, र consumer ले {"age": "twenty-five"} पठाउन सक्छ जब तपाईं {"age": 25} expect गर्नुहुन्छ। JSON Schema ले यो समस्या solve गर्छ — JSON documents को structure, types र constraints describe गर्ने vocabulary प्रदान गर्छ। एउटा JSON Schema generator ले तपाईंको sample JSON लिएर automatically Schema produce गर्छ।

नेपालको growing IT sector मा — चाहे Kathmandu को startups होस् वा Pokhara को freelancers — JSON Schema ले API development लाई professional र maintainable बनाउँछ। यो guide मा JSON Schema को foundation देखि advanced patterns सम्म सबै कुरा छ।

Free Tool

आफ्नो JSON बाट Schema Generate गर्नुहोस्

कुनै पनि JSON object paste गर्नुहोस् र तुरुन्त valid JSON Schema पाउनुहोस्। Draft 4, 7 र 2020-12 support। निःशुल्क, login आवश्यक छैन।

JSON Schema Generator खोल्नुहोस्

JSON Schema के हो र Developers ले किन प्रयोग गर्छन्?

JSON Schema एउटा declarative language हो JSON documents annotate र validate गर्नको लागि। Current stable release Draft 2020-12 हो।

JSON Schema ले के गर्छ

  • Validation — Runtime मा verify गर्नुहोस् कि JSON data expected structure follow गर्छ
  • Documentation — Self-documenting API contracts जुन humans र machines दुवैले read गर्न सक्छन्
  • Code generation — Schema बाट TypeScript interfaces, Python dataclasses, Go structs generate गर्नुहोस्
  • UI generation — react-jsonschema-form जस्ता tools ले schema बाट automatically forms render गर्छन्

Simple Schema Example

// Sample JSON:
{
  "id": 42,
  "username": "ramkrishna",
  "email": "ram@example.com.np",
  "active": true
}

// Generated JSON Schema:
{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "type": "object",
  "properties": {
    "id":       { "type": "integer" },
    "username": { "type": "string", "minLength": 3, "maxLength": 30 },
    "email":    { "type": "string", "format": "email" },
    "active":   { "type": "boolean" }
  },
  "required": ["id", "username", "email"],
  "additionalProperties": false
}

JSON Schema Keywords: Data Types र Constraints को सम्पूर्ण Reference

Core Data Types

TypeExample ValuesType-Specific Keywords
string"नमस्ते", "2026-03-19"minLength, maxLength, pattern, format
integer42, -7minimum, maximum, multipleOf
number3.14, 42minimum, maximum
booleantrue, false
array[1, 2, 3]items, minItems, maxItems, uniqueItems
object{"key": "val"}properties, required, additionalProperties
nullnull

String Format Keywords

{
  "type": "string",
  "format": "email"
  // अरू formats: uri, uuid, date, date-time, ipv4, ipv6, hostname
}

Conditional Validation (if/then/else)

{
  "type": "object",
  "properties": {
    "accountType": { "enum": ["व्यक्तिगत", "व्यावसायिक"] },
    "companyName": { "type": "string" }
  },
  "if": {
    "properties": { "accountType": { "const": "व्यावसायिक" } }
  },
  "then": {
    "required": ["companyName"]   // व्यावसायिक account मा company required
  }
}

Validation Constraints: required, additionalProperties, enum र pattern

required — अनिवार्य Fields

{
  "type": "object",
  "properties": {
    "id":       { "type": "integer" },
    "email":    { "type": "string", "format": "email" },
    "password": { "type": "string", "minLength": 8 },
    "nickname": { "type": "string" }    // Optional
  },
  "required": ["id", "email", "password"]
}

महत्वपूर्ण: properties ≠ required

// गलत बुझाइ — properties ले enforce गर्दैन:
{
  "type": "object",
  "properties": { "name": { "type": "string" } }
}
// {} VALID छ! properties ले भन्छ: "यदि name छ भने string हुनुपर्छ"
// तर छैन भने पनि OK छ।

// सही — required अलग लेख्नुपर्छ:
{
  "type": "object",
  "properties": { "name": { "type": "string" } },
  "required": ["name"]
}

pattern — Regex Validation

{
  "username":    { "pattern": "^[a-zA-Z0-9_]{3,30}$" },
  "nepaliPhone": { "pattern": "^\+977[9][6-9]\d{8}$" },  // Nepal mobile
  "slug":        { "pattern": "^[a-z0-9]+(?:-[a-z0-9]+)*$" }
}

API Development मा JSON Schema: OpenAPI, Swagger र TypeScript

OpenAPI 3.1 सँग JSON Schema

openapi: 3.1.0
components:
  schemas:
    CreateUserRequest:
      type: object
      properties:
        username:
          type: string
          minLength: 3
        email:
          type: string
          format: email
        password:
          type: string
          minLength: 8
          writeOnly: true
      required: [username, email, password]
      additionalProperties: false

Node.js मा Ajv Runtime Validation

import Ajv from 'ajv';
import addFormats from 'ajv-formats';

const ajv = new Ajv({ allErrors: true });
addFormats(ajv);

const validate = ajv.compile(userSchema);
const data = { email: "invalid-email", age: -5 };

if (!validate(data)) {
  console.error(validate.errors);
  // [{ instancePath: '/email', message: 'must match format "email"' }]
}

JSON Schema vs TypeScript Interfaces vs Zod: कहिले के प्रयोग गर्ने

FeatureJSON SchemaTypeScript InterfaceZod
Runtime validationहो (Ajv)छैनहो (built-in)
Compile-time typesCodegen बाटहो (native)हो (z.infer)
Language-agnosticहोछैनछैन
OpenAPI integrationNativeVia decoratorszod-to-openapi
Bundle size~30kbZero~8kb

निर्णय Framework

JSON Schema प्रयोग गर्नुहोस् जब:
  ✓ Language-agnostic APIs (Go, Python consumers पनि छन्)
  ✓ OpenAPI/Swagger documentation आवश्यक छ
  ✓ Config files को लागि IDE support चाहिन्छ

TypeScript Interface प्रयोग गर्नुहोस् जब:
  ✓ Pure TypeScript codebase, runtime validation नचाहिने
  ✓ Performance-critical code

Zod प्रयोग गर्नुहोस् जब:
  ✓ Next.js, tRPC, Remix fullstack apps
  ✓ Types र runtime validation एकैचोटि चाहिन्छ

सामान्य JSON Schema गल्तीहरू र Validation Errors Fix गर्ने तरिका

गल्ती १: additionalProperties + allOf Bug

// गलत (Draft 4-7 मा):
{
  "allOf": [{ "$ref": "#/$defs/Base" }],
  "additionalProperties": false  // Base को properties देख्दैन!
}

// सही (Draft 2020-12):
{
  "allOf": [{ "$ref": "#/$defs/Base" }],
  "unevaluatedProperties": false  // सबै subschemas को properties देख्छ
}

गल्ती २: Pattern मा Double Escaping

// गलत:
{ "pattern": "^d{3}-d{4}$" }   // JSON parse error

// सही (JSON string मा double backslash):
{ "pattern": "^\d{3}-\d{4}$" }

गल्ती ३: Null vs Missing Property

// Absent: { "id": 1 }              (key छैन)
// Null:   { "id": 1, "bio": null } (key छ, value null छ)

// दुवै allow गर्न (Draft 2020-12 shorthand):
{
  "properties": {
    "bio": { "type": ["string", "null"] }
  }
  // "bio" required[] मा छैन — absent पनि valid
}

$ref र $defs बाट Schema Reuse

{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$defs": {
    "Address": {
      "type": "object",
      "properties": {
        "tole":    { "type": "string" },
        "shahar":  { "type": "string" },
        "zilla":   { "type": "string" }
      },
      "required": ["tole", "shahar", "zilla"]
    }
  },
  "type": "object",
  "properties": {
    "billingAddress":  { "$ref": "#/$defs/Address" },
    "shippingAddress": { "$ref": "#/$defs/Address" }
  }
}

यस approach बाट:

  • Address schema एक ठाउँ define भएको छ — दुई ठाउँ reuse हुन्छ
  • Address change गर्दा दुवै references automatically update हुन्छन्
  • Schema सानो र maintainable रहन्छ

How to Use the Tool (Step by Step)

  1. 1

    Sample JSON paste गर्नुहोस्

    API response, config file वा database record बाट real JSON object copy गरेर input panel मा paste गर्नुहोस्।

  2. 2

    Draft version select गर्नुहोस्

    JSON Schema draft choose गर्नुहोस्: नयाँ projects को लागि Draft 2020-12, maximum tool compatibility को लागि Draft 7, legacy systems को लागि Draft 4।

  3. 3

    Generation options configure गर्नुहोस्

    Choose गर्नुहोस्: सबै keys required मा राख्ने हो कि होइन, string formats detect गर्ने (email, URI, date-time), additionalProperties false गर्ने हो कि होइन।

  4. 4

    Schema generate गर्नुहोस्

    Generate click गर्नुहोस्। Tool ले types infer गर्छ, formats detect गर्छ, nested structures identify गर्छ र १ second मा complete valid JSON Schema produce गर्छ।

  5. 5

    Review र refine गर्नुहोस्

    Generated schema starting point हो। Manually refine गर्नुहोस्: optional fields required[] बाट हटाउनुहोस्, numbers को लागि minimum/maximum थप्नुहोस्।

  6. 6

    Sample data validate गर्नुहोस्

    Inline validator बाट schema को against multiple JSON examples test गर्नुहोस्। Production मा ship गर्नु अघि validation errors पत्ता लगाउनुहोस्।

Frequently Asked Questions

JSON Schema Draft 4, 7 र 2020-12 मा के फरक छ?+

Draft 4 (2013) ले foundation set गर्यो — type, properties, required, allOf/anyOf/oneOf. Draft 7 (2018) ले if/then/else conditional validation, readOnly, writeOnly थप्यो। Draft 2020-12 current standard हो: unevaluatedProperties (additionalProperties+allOf bug fix), tuples को लागि prefixItems, र improved $ref semantics। New projects को लागि Draft 2020-12 प्रयोग गर्नुहोस्।

JSON Schema बाट TypeScript types कसरी generate गर्ने?+

json-schema-to-typescript package (json2ts CLI) ले कुनै पनि JSON Schema file बाट TypeScript interfaces generate गर्छ। Run गर्नुहोस्: npm install -g json-schema-to-typescript && json2ts -i schema.json -o types.ts. वा Zod को साथ zod-to-json-schema प्रयोग गर्नुहोस् — TypeScript मा एक single source of truth राख्नुहोस् जसले types र JSON Schema दुवै produce गर्छ।

Node.js मा best JSON Schema validator library कुन हो?+

Ajv (Another JSON Validator) industry standard हो — fastest, most spec-compliant र millions of packages ले प्रयोग गर्छन्। Install गर्नुहोस्: npm install ajv ajv-formats (email, uri, date-time format validation को लागि)। Ajv version 8 ले default मा Draft 2020-12 support गर्छ।

Nepal को projects मा JSON Schema कि Zod?+

TypeScript-only Next.js वा Node.js projects को लागि Zod simpler छ — types र runtime validation एउटै declaration बाट excellent error messages सहित पाइन्छ। OpenAPI docs पनि चाहिन्छ भने zod-to-openapi package थप्नुहोस्। JSON Schema directly tab प्रयोग गर्नुहोस् जब language-agnostic validation चाहिन्छ वा non-TypeScript services (Python, Go) ले schemas consume गर्छन्।

Free — No Signup Required

आफ्नो JSON बाट Schema Generate गर्नुहोस्

कुनै पनि JSON object paste गर्नुहोस् र तुरुन्त valid JSON Schema पाउनुहोस्। Draft 4, 7 र 2020-12 support। निःशुल्क, login आवश्यक छैन।

JSON Schema Generator खोल्नुहोस्

Related Guides