📊 Ö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
📖 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
🌟 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