🐰 RabbitJSON v2.1.1

Tüm Örnekler Deposu - Classic ASP JSON İşleme Kütüphanesi

📊 Örnek JSON Verisi

Bu dokümantasyonda kullanacağımız kapsamlı JSON verisi:

{ "metadata": { "version": "2.1.0", "generatedAt": "2025-01-20T15:35:00Z", "source": "RabbitJSON Sample Data" }, "company": { "name": "RabbitCMS Technology", "founded": 2020, "headquarters": { "country": "Turkey", "city": "Istanbul", "coordinates": { "latitude": 41.0082, "longitude": 28.9784 } }, "employees": 250, "isPublic": false }, "products": [ { "id": 1001, "name": "RabbitJSON Library", "category": "Development Tools", "price": 0.00, "isOpenSource": true, "features": ["Fast parsing", "Error handling", "Path-based access"], "downloads": { "total": 15847, "thisMonth": 2341, "avgPerDay": 78 } }, { "id": 1002, "name": "RabbitCMS Pro", "category": "Content Management", "price": 299.99, "isOpenSource": false, "features": ["Multi-language", "SEO optimization", "User management"] } ], "users": [ { "id": 12345, "username": "john_developer", "profile": { "firstName": "John", "lastName": "Smith", "age": 32, "country": "USA" }, "subscription": { "plan": "premium", "startDate": "2024-03-15", "autoRenew": true } }, { "id": 12346, "username": "ayse_frontend", "profile": { "firstName": "Ayşe", "lastName": "Demir", "age": 28, "country": "Turkey" } } ], "analytics": { "traffic": { "dailyVisitors": 2847, "pageViews": 145623, "bounceRate": 0.32 }, "geographical": { "topCountries": [ {"country": "USA", "percentage": 35.2, "visitors": 23864}, {"country": "Turkey", "percentage": 18.7, "visitors": 12695}, {"country": "Germany", "percentage": 12.4, "visitors": 8419} ] } } }

📋 Veri Yapısı Özellikleri

  • Nested Objects: company.headquarters.coordinates
  • Arrays: products[], users[], topCountries[]
  • Mixed Types: String, Number, Boolean, Null
  • Complex Structures: Array içinde object, object içinde array

🔧 Parse() Method Örnekleri

1. Basit JSON String Parse

<% ' JSON string'ini parse et Set json = CreateRabbitJSON() Set result = json.Parse("{""name"":""John"",""age"":30}") If Not (result Is Nothing) Then Response.Write "Parse başarılı!" Response.Write "<br>İsim: " & json.GetValue("name", "") Response.Write "<br>Yaş: " & json.GetValue("age", 0) Else Response.Write "Parse hatası: " & json.LastError End If %>

🎯 Ne İşe Yarar?

JSON string'ini VBScript Dictionary objesine çevirir. Parse başarısızsa Nothing döner.

🚀 Nasıl Kullanılır?

  • CreateRabbitJSON() ile instance oluştur
  • Parse() methoduna JSON string'i ver
  • Sonucu kontrol et (Nothing olabilir)
  • GetValue() ile verilere eriş

2. Kompleks JSON Parse

<% ' Kompleks JSON yapısı Dim complexJSON complexJSON = "{""company"":{""name"":""RabbitCMS""," complexJSON = complexJSON & """employees"":[{""name"":""John"",""role"":""Dev""}," complexJSON = complexJSON & "{""name"":""Jane"",""role"":""Designer""}]}}" Set json = CreateRabbitJSON() Set result = json.Parse(complexJSON) If Not (result Is Nothing) Then ' Şirket adı companyName = json.GetValue("company.name", "") ' İlk çalışan firstEmployee = json.GetValue("company.employees.0.name", "") firstRole = json.GetValue("company.employees.0.role", "") Response.Write "Şirket: " & companyName & "<br>" Response.Write "İlk Çalışan: " & firstEmployee & " (" & firstRole & ")" End If %>

🎯 Ne İşe Yarar?

Nested obje ve array yapılarını parse eder. Path notation ile derinlemesine erişim sağlar.

🚀 Nasıl Kullanılır?

  • Karmaşık JSON'lar için ideal
  • Dot notation: "company.name"
  • Array access: "employees.0.name"
  • Unlimited nesting depth

3. Error Handling ile Parse

<% Set json = CreateRabbitJSON() ' Geçersiz JSON test Set result = json.Parse("{invalid json}") If result Is Nothing Then Response.Write "<div style='color:red'>" Response.Write "❌ Parse Hatası: " & json.LastError Response.Write "</div>" ' Hata temizle json.ClearError() ' Tekrar dene - geçerli JSON ile Set result = json.Parse("{""status"":""ok""}") If Not (result Is Nothing) Then Response.Write "<div style='color:green'>" Response.Write "✅ İkinci deneme başarılı!" Response.Write "</div>" End If End If %>

🎯 Ne İşe Yarar?

Parse hatalarını yakalar ve yönetir. Production ortamında güvenli JSON işleme sağlar.

🚀 Nasıl Kullanılır?

  • Her zaman Nothing kontrolü yap
  • LastError ile hata mesajını al
  • ClearError() ile hata temizle
  • Try-again mantığı uygula

🌐 URL'den JSON Yükleme

1. HTTP API'den Veri Çekme

<% ' API'den direkt JSON yükle Set json = CreateRabbitJSON() Set result = json.Parse("https://jsonplaceholder.typicode.com/users/1") If Not (result Is Nothing) Then userName = json.GetValue("name", "Bilinmiyor") userEmail = json.GetValue("email", "Bilinmiyor") userCompany = json.GetValue("company.name", "Bilinmiyor") Response.Write "<h4>API'den Gelen Veri:</h4>" Response.Write "👤 Kullanıcı: " & userName & "<br>" Response.Write "📧 Email: " & userEmail & "<br>" Response.Write "🏢 Şirket: " & userCompany Else Response.Write "API Error: " & json.LastError End If %>

🎯 Ne İşe Yarar?

HTTP/HTTPS URL'lerden direkt JSON verisi çeker. API entegrasyonu için ideal.

🚀 Nasıl Kullanılır?

  • Parse() methoduna URL ver
  • HTTP GET request otomatik yapılır
  • 200 OK response beklenir
  • JSON response parse edilir
  • Network hatalarını handle et

2. GitHub API Entegrasyonu

<% ' GitHub API'den user bilgisi çek Set json = CreateRabbitJSON() Set result = json.Parse("https://api.github.com/users/octocat") If Not (result Is Nothing) Then login = json.GetValue("login", "") name = json.GetValue("name", "") followers = json.GetValue("followers", 0) publicRepos = json.GetValue("public_repos", 0) Response.Write "<div style='border:1px solid #ccc; padding:15px; border-radius:8px'>" Response.Write "<h4>🐙 GitHub Profile</h4>" Response.Write "Username: <strong>" & login & "</strong><br>" Response.Write "Name: " & name & "<br>" Response.Write "Followers: " & FormatNumber(followers, 0) & "<br>" Response.Write "Public Repos: " & publicRepos Response.Write "</div>" End If %>

🎯 Ne İşe Yarar?

Gerçek API'lerden canlı veri çeker. Sosyal medya, havadurumu, finans API'leri için kullanılabilir.

🚀 Nasıl Kullanılır?

  • Public API'ler için authentication gerekmez
  • Rate limiting'e dikkat et
  • Cache mekanizması düşün
  • Timeout ve retry mantığı ekle

📖 GetValue() Method Örnekleri

1. Basit Veri Erişimi

<% ' Sample data parse et Set json = CreateRabbitJSON() json.Parse "{""name"":""Mehmet"",""age"":30,""active"":true,""salary"":null}" ' Farklı tip değerler al userName = json.GetValue("name", "Bilinmiyor") ' String userAge = json.GetValue("age", 0) ' Number isActive = json.GetValue("active", False) ' Boolean userSalary = json.GetValue("salary", "Belirtilmemiş") ' Null değer userPhone = json.GetValue("phone", "Yok") ' Olmayan key Response.Write "👤 İsim: " & userName & "<br>" Response.Write "🎂 Yaş: " & userAge & "<br>" Response.Write "✅ Aktif: " & isActive & "<br>" Response.Write "💰 Maaş: " & userSalary & "<br>" Response.Write "📱 Telefon: " & userPhone %>

🎯 Ne İşe Yarar?

JSON'dan güvenli şekilde değer alır. Değer yoksa veya null ise default değer döner.

🚀 Nasıl Kullanılır?

  • GetValue(path, defaultValue) formatında kullan
  • Default değer tipine dikkat et
  • Null değerler için anlamlı default ver
  • Olmayan key'ler için fallback sağla

2. Nested Object Erişimi

<% ' Derinlemesine nested JSON Set json = CreateRabbitJSON() Dim nestedJSON nestedJSON = "{""user"":{""profile"":{""personal"":{""name"":""Ali""," nestedJSON = nestedJSON & """age"":25},""contact"":{""email"":""[email protected]""," nestedJSON = nestedJSON & """phone"":""+90555123456""}},""settings"":{""theme"":""dark""," nestedJSON = nestedJSON & """language"":""tr""}}}" json.Parse(nestedJSON) ' Derin path erişimi userName = json.GetValue("user.profile.personal.name", "") userAge = json.GetValue("user.profile.personal.age", 0) userEmail = json.GetValue("user.profile.contact.email", "") userTheme = json.GetValue("user.settings.theme", "light") userLang = json.GetValue("user.settings.language", "en") Response.Write "<h4>👤 Kullanıcı Profili</h4>" Response.Write "İsim: " & userName & "<br>" Response.Write "Yaş: " & userAge & "<br>" Response.Write "Email: " & userEmail & "<br>" Response.Write "Tema: " & userTheme & "<br>" Response.Write "Dil: " & userLang %>

🎯 Ne İşe Yarar?

Çok katmanlı JSON yapılarında dot notation ile derinlemesine erişim sağlar.

🚀 Nasıl Kullanılır?

  • Nokta ile ayır: "user.profile.name"
  • Unlimited depth desteği
  • Her seviyede null kontrolü
  • Path bulunamazsa default döner

3. Array Elemanlarına Erişim

<% ' Array içeren JSON Set json = CreateRabbitJSON() Dim arrayJSON arrayJSON = "{""products"":[{""id"":1,""name"":""Laptop"",""price"":999.99}," arrayJSON = arrayJSON & "{""id"":2,""name"":""Mouse"",""price"":29.99}," arrayJSON = arrayJSON & "{""id"":3,""name"":""Keyboard"",""price"":79.99}]," arrayJSON = arrayJSON & """categories"":[""Electronics"",""Computers"",""Accessories""]}" json.Parse(arrayJSON) ' Array elemanlarına erişim (0-based index) firstProduct = json.GetValue("products.0.name", "") firstPrice = json.GetValue("products.0.price", 0) secondProduct = json.GetValue("products.1.name", "") thirdProduct = json.GetValue("products.2.name", "") ' String array erişimi firstCategory = json.GetValue("categories.0", "") secondCategory = json.GetValue("categories.1", "") Response.Write "<h4>🛍️ Ürünler</h4>" Response.Write "1. " & firstProduct & " - $" & firstPrice & "<br>" Response.Write "2. " & secondProduct & "<br>" Response.Write "3. " & thirdProduct & "<br>" Response.Write "<h4>📂 Kategoriler</h4>" Response.Write "• " & firstCategory & "<br>" Response.Write "• " & secondCategory %>

🎯 Ne İşe Yarar?

Array elemanlarına index ile erişim sağlar. Hem object array hem string array destekler.

🚀 Nasıl Kullanılır?

  • Array index: "products.0", "products.1"
  • 0-based indexing (0, 1, 2, 3...)
  • Object array: "products.0.name"
  • String array: "categories.0"
  • Geçersiz index için default döner

🔄 Loop & İterasyon Örnekleri

1. Array Üzerinde Loop

<% ' Ürün listesi JSON'u Set json = CreateRabbitJSON() Dim productJSON productJSON = "{""products"":[{""name"":""Laptop"",""price"":999}," productJSON = productJSON & "{""name"":""Mouse"",""price"":29}," productJSON = productJSON & "{""name"":""Keyboard"",""price"":79}]}" json.Parse(productJSON) ' Array uzunluğunu bul (manuel olarak) Dim productCount, i productCount = 0 Do While json.HasValue("products." & productCount) productCount = productCount + 1 Loop Response.Write "<h4>🛒 Ürün Listesi (" & productCount & " adet)</h4>" Response.Write "<ul>" ' Array üzerinde loop For i = 0 To productCount - 1 productName = json.GetValue("products." & i & ".name", "") productPrice = json.GetValue("products." & i & ".price", 0) If productName <> "" Then Response.Write "<li>" & productName & " - $" & productPrice & "</li>" End If Next Response.Write "</ul>" %>

🎯 Ne İşe Yarar?

JSON array'lerinde tüm elemanları dolaşır. E-commerce, kullanıcı listeleri için ideal.

🚀 Nasıl Kullanılır?

  • HasValue() ile array uzunluğu bul
  • For i = 0 To count-1 ile dolaş
  • "arrayName." & i & ".property" formatı
  • Empty kontrolü yap

2. Nested Object Loop

<% ' Kullanıcı listesi Set json = CreateRabbitJSON() Dim userJSON userJSON = "{""users"":[{""name"":""John"",""role"":""Admin"",""active"":true}," userJSON = userJSON & "{""name"":""Jane"",""role"":""Editor"",""active"":false}," userJSON = userJSON & "{""name"":""Bob"",""role"":""User"",""active"":true}]}" json.Parse(userJSON) ' Kullanıcı sayısını bul Dim userCount, i userCount = 0 Do While json.HasValue("users." & userCount) userCount = userCount + 1 Loop Response.Write "<h4>👥 Kullanıcı Listesi</h4>" Response.Write "<table border='1' style='border-collapse:collapse'>" Response.Write "<tr><th>İsim</th><th>Rol</th><th>Durum</th></tr>" For i = 0 To userCount - 1 userName = json.GetValue("users." & i & ".name", "") userRole = json.GetValue("users." & i & ".role", "") isActive = json.GetValue("users." & i & ".active", False) Dim statusText, statusColor If isActive Then statusText = "Aktif" statusColor = "green" Else statusText = "Pasif" statusColor = "red" End If Response.Write "<tr>" Response.Write "<td>" & userName & "</td>" Response.Write "<td>" & userRole & "</td>" Response.Write "<td style='color:" & statusColor & "'>" & statusText & "</td>" Response.Write "</tr>" Next Response.Write "</table>" %>

🎯 Ne İşe Yarar?

Karmaşık object array'lerini tablo formatında gösterir. Admin panelleri için mükemmel.

🚀 Nasıl Kullanılır?

  • Multiple property access
  • Conditional logic (if-else)
  • HTML table generation
  • Data formatting

3. Dictionary Keys ile Loop

<% ' Configuration objesi Set json = CreateRabbitJSON() Dim configJSON configJSON = "{""database"":{""host"":""localhost"",""port"":3306,""name"":""mydb""}," configJSON = configJSON & """cache"":{""enabled"":true,""ttl"":3600,""provider"":""redis""}," configJSON = configJSON & """email"":{""smtp"":""smtp.gmail.com"",""port"":587}}" json.Parse(configJSON) ' Root level keys'leri al Dim allKeys, i allKeys = json.GetKeys() Response.Write "<h4>⚙️ Konfigürasyon Ayarları</h4>" For i = 0 To UBound(allKeys) Dim currentKey currentKey = allKeys(i) Response.Write "<h5>📂 " & UCase(currentKey) & "</h5>" Response.Write "<ul>" ' Her kategorinin alt ayarlarını listele Select Case currentKey Case "database" Response.Write "<li>Host: " & json.GetValue("database.host", "") & "</li>" Response.Write "<li>Port: " & json.GetValue("database.port", 0) & "</li>" Response.Write "<li>Database: " & json.GetValue("database.name", "") & "</li>" Case "cache" Response.Write "<li>Enabled: " & json.GetValue("cache.enabled", False) & "</li>" Response.Write "<li>TTL: " & json.GetValue("cache.ttl", 0) & " seconds</li>" Response.Write "<li>Provider: " & json.GetValue("cache.provider", "") & "</li>" Case "email" Response.Write "<li>SMTP: " & json.GetValue("email.smtp", "") & "</li>" Response.Write "<li>Port: " & json.GetValue("email.port", 0) & "</li>" End Select Response.Write "</ul>" Next %>

🎯 Ne İşe Yarar?

JSON objesinin key'lerini dinamik olarak dolaşır. Configuration management için ideal.

🚀 Nasıl Kullanılır?

  • GetKeys() ile key array'i al
  • UBound() ile array uzunluğu
  • Select Case ile key bazlı işlem
  • Dynamic path building

✏️ SetValue() Method Örnekleri

1. Basit Veri Yazma

<% ' Boş JSON'dan başla Set json = CreateRabbitJSON() json.Parse("{}") ' Basit değerler set et json.SetValue "name", "Mehmet" json.SetValue "age", 30 json.SetValue "active", True json.SetValue "salary", 5000.50 ' Sonucu göster result = json.Stringify(json.Data, 2) Response.Write "<h4>✅ Oluşturulan JSON:</h4>" Response.Write "<pre>" & result & "</pre>" ' Değerleri oku Response.Write "<h4>📖 Okunan Değerler:</h4>" Response.Write "İsim: " & json.GetValue("name", "") & "<br>" Response.Write "Yaş: " & json.GetValue("age", 0) & "<br>" Response.Write "Aktif: " & json.GetValue("active", False) & "<br>" Response.Write "Maaş: " & FormatCurrency(json.GetValue("salary", 0)) %>

🎯 Ne İşe Yarar?

JSON objesine yeni değerler ekler veya mevcut değerleri günceller. Dinamik veri oluşturma için ideal.

🚀 Nasıl Kullanılır?

  • SetValue(path, value) formatında kullan
  • Farklı veri tiplerini destekler
  • Root level property'ler için basit path
  • Otomatik tip detection

🌟 Gerçek Hayat Uygulamaları

1. E-Commerce Sepet Yönetimi

<% ' Sepet JSON'u oluştur Set json = CreateRabbitJSON() json.Parse("{}") ' Sepet bilgileri json.SetValue "cart.sessionId", Session.SessionID json.SetValue "cart.customerId", 12345 json.SetValue "cart.currency", "TRY" ' Ürünleri sepete ekle json.SetValue "cart.items.0.productId", 1001 json.SetValue "cart.items.0.name", "MacBook Pro 14" json.SetValue "cart.items.0.price", 25999.99 json.SetValue "cart.items.0.quantity", 1 json.SetValue "cart.items.1.productId", 1002 json.SetValue "cart.items.1.name", "Magic Mouse" json.SetValue "cart.items.1.price", 699.99 json.SetValue "cart.items.1.quantity", 2 ' Sepet toplamları hesapla Dim totalAmount, i totalAmount = 0 For i = 0 To 1 quantity = json.GetValue("cart.items." & i & ".quantity", 0) price = json.GetValue("cart.items." & i & ".price", 0) totalAmount = totalAmount + (quantity * price) Next json.SetValue "cart.totals.subtotal", totalAmount json.SetValue "cart.totals.tax", totalAmount * 0.18 json.SetValue "cart.totals.total", totalAmount * 1.18 ' Sepet göster Response.Write "<h4>🛒 Alışveriş Sepeti</h4>" For i = 0 To 1 productName = json.GetValue("cart.items." & i & ".name", "") quantity = json.GetValue("cart.items." & i & ".quantity", 0) price = json.GetValue("cart.items." & i & ".price", 0) Response.Write "• " & productName & " (x" & quantity & ") - " & FormatCurrency(price * quantity) & "<br>" Next Response.Write "<strong>Toplam: " & FormatCurrency(json.GetValue("cart.totals.total", 0)) & "</strong>" %>

🎯 Ne İşe Yarar?

E-commerce sepet sistemi. Ürün ekleme, toplam hesaplama, session yönetimi.

🚀 Nasıl Kullanılır?

  • Session-based cart storage
  • Dynamic price calculation
  • Tax & total management
  • Product quantity handling

2. API Response Builder

<% ' API Response oluştur Set json = CreateRabbitJSON() json.Parse("{}") ' Response metadata json.SetValue "status", "success" json.SetValue "message", "Data retrieved successfully" json.SetValue "timestamp", Now() json.SetValue "version", "2.1.1" ' User data ekle json.SetValue "data.users.0.id", 1001 json.SetValue "data.users.0.username", "john_doe" json.SetValue "data.users.0.email", "[email protected]" json.SetValue "data.users.0.role", "admin" json.SetValue "data.users.0.lastLogin", "2025-01-20" json.SetValue "data.users.1.id", 1002 json.SetValue "data.users.1.username", "jane_smith" json.SetValue "data.users.1.email", "[email protected]" json.SetValue "data.users.1.role", "user" json.SetValue "data.users.1.lastLogin", "2025-01-19" ' Pagination bilgisi json.SetValue "meta.totalCount", 245 json.SetValue "meta.currentPage", 1 json.SetValue "meta.perPage", 10 json.SetValue "meta.totalPages", 25 ' JSON response'u oluştur Response.ContentType = "application/json" Response.Write json.StringifyCompact(json.Data) ' Debug için HTML output (production'da remove et) Response.Write "<br><h4>🔍 Debug Output:</h4>" Response.Write "<pre>" & json.Stringify(json.Data, 2) & "</pre>" %>

🎯 Ne İşe Yarar?

REST API endpoint'leri için standart JSON response format'ı oluşturur.

🚀 Nasıl Kullanılır?

  • Standard API response structure
  • Response.ContentType ayarla
  • Pagination metadata
  • Error handling patterns

3. Configuration Management

<% ' Environment-based config Set json = CreateRabbitJSON() json.Parse("{}") ' Environment detect (örnek) Dim currentEnv currentEnv = "development" ' production'da farklı logic ' Base settings json.SetValue "app.name", "RabbitJSON Application" json.SetValue "app.version", "2.1.1" ' Environment-specific If currentEnv = "development" Then json.SetValue "database.host", "localhost" json.SetValue "database.name", "myapp_dev" json.SetValue "debug.enabled", True json.SetValue "cache.enabled", False ElseIf currentEnv = "production" Then json.SetValue "database.host", "prod-server.com" json.SetValue "database.name", "myapp_prod" json.SetValue "debug.enabled", False json.SetValue "cache.enabled", True End If ' Security settings json.SetValue "security.sessionTimeout", 30 json.SetValue "security.maxLoginAttempts", 5 ' Feature flags json.SetValue "features.newDashboard", True json.SetValue "features.betaFeatures", (currentEnv <> "production") ' Application-level'da sakla Application("AppConfig") = json.StringifyCompact(json.Data) Response.Write "<h4>⚙️ " & UCase(currentEnv) & " Configuration</h4>" Response.Write "<pre>" & json.Stringify(json.Data, 2) & "</pre>" ' Kullanım örneği Response.Write "<h5>📖 Config Kullanımı:</h5>" Response.Write "Database Host: " & json.GetValue("database.host", "") & "<br>" Response.Write "Debug Mode: " & json.GetValue("debug.enabled", False) & "<br>" Response.Write "Cache: " & IIf(json.GetValue("cache.enabled", False), "Enabled", "Disabled") %>

🎯 Ne İşe Yarar?

Çoklu environment için dinamik konfigürasyon yönetimi sağlar.

🚀 Nasıl Kullanılır?

  • Environment detection
  • Feature flag management
  • Application-level storage
  • Conditional configuration

🛠️ Utility Methods & Advanced Usage

1. Error Handling & Debugging

<% Set json = CreateRabbitJSON() ' Error test scenarios Dim testCases(3) testCases(0) = "{""valid"": ""json""}" ' Valid testCases(1) = "{invalid json}" ' Invalid syntax testCases(2) = "" ' Empty testCases(3) = "https://invalid-url.com" ' Invalid URL Response.Write "<h4>🧪 Error Handling Tests</h4>" For i = 0 To 3 Response.Write "<h5>Test " & (i+1) & ":</h5>" Set result = json.Parse(testCases(i)) If result Is Nothing Then Response.Write "<div style='color:red; border:1px solid red; padding:10px'>" Response.Write "❌ Error: " & json.LastError Response.Write "</div>" json.ClearError() Else Response.Write "<div style='color:green; border:1px solid green; padding:10px'>" Response.Write "✅ Success! Items: " & json.Count Response.Write "</div>" End If Response.Write "<br>" Next ' HasError test json.Parse("{invalid}") If json.HasError() Then Response.Write "<p>Error detected: " & json.LastError & "</p>" json.ClearError() Response.Write "<p>Error cleared successfully!</p>" End If %>

🎯 Ne İşe Yarar?

JSON parse hatalarını yakalayıp güvenli bir şekilde yönetir.

🚀 Nasıl Kullanılır?

  • Her Parse() sonrası Nothing kontrolü
  • LastError ile hata detayları
  • ClearError() ile reset
  • HasError() ile durum kontrolü

2. Data Validation & Type Checking

<% ' Sample user data validate et Set json = CreateRabbitJSON() json.Parse("{""user"":{""name"":""John"",""age"":30,""email"":""[email protected]"",""active"":true}}" ' Validation rules Response.Write "<h4>✅ Data Validation Results</h4>" ' Required fields check requiredFields = Array("user.name", "user.email", "user.age") allValid = True For Each field In requiredFields If json.HasValue(field) Then value = json.GetValue(field, "") If value <> "" And Not IsNull(value) Then Response.Write "✅ " & field & ": " & value & "<br>" Else Response.Write "❌ " & field & ": Empty or null<br>" allValid = False End If Else Response.Write "❌ " & field & ": Missing<br>" allValid = False End If Next ' Type validation age = json.GetValue("user.age", 0) If IsNumeric(age) And age > 0 And age < 120 Then Response.Write "✅ Age validation: Valid (" & age & ")<br>" Else Response.Write "❌ Age validation: Invalid<br>" allValid = False End If ' Email validation (basit) email = json.GetValue("user.email", "") If InStr(email, "@") > 0 And InStr(email, ".") > 0 Then Response.Write "✅ Email validation: Valid (" & email & ")<br>" Else Response.Write "❌ Email validation: Invalid<br>" allValid = False End If Response.Write "<br><strong>Overall Result: " If allValid Then Response.Write "<span style='color:green'>✅ All validations passed</span>" Else Response.Write "<span style='color:red'>❌ Some validations failed</span>" End If Response.Write "</strong>" %>

🎯 Ne İşe Yarar?

JSON verilerinde data validation ve type checking yapar.

🚀 Nasıl Kullanılır?

  • HasValue() ile field existence
  • Type validation (IsNumeric, etc.)
  • Business rule validation
  • Batch validation loops

⚡ Performans İpuçları & Best Practices

💡 Performans İpuçları

  • StringifyCompact() kullan: Network transferleri için kompakt format tercih et
  • Application-level cache: Büyük JSON'ları Application("key") ile cache'le
  • Lazy loading: Büyük array'lerde sadece gerekli indexleri yükle
  • Error handling: Her Parse() sonrası Nothing kontrolü yap
  • Memory management: Büyük objeler için Set obj = Nothing kullan

✅ Best Practices

  • Consistent naming: camelCase veya snake_case konvansiyonu belirle
  • Default values: GetValue() ile her zaman default değer ver
  • API versioning: JSON response'larında version bilgisi ekle
  • Content-Type: API endpoint'lerinde "application/json" header'ı kullan
  • Security: User input'u validate et, XSS koruması yap

📚 Sık Kullanılan Patterns

  • Config management: Environment-based ayarlar için
  • API responses: Standard response format (status, data, meta)
  • Session storage: Complex data'yı session'da JSON olarak sakla
  • Logging: Structured logging için JSON format kullan
  • Cache keys: JSON hash'i ile cache key oluştur