Skip to content

Examples ​

Here are some real-world examples of VZparse usage:

Basic Configuration ​

vz
# Application configuration
app: {
  name: "MyApp"
  version: "1.0.0"
  debug: true
  port: 3000
}

# Database configuration
database: {
  host: "localhost"
  port: 5432
  name: "myapp"
  ssl: true
}

# Feature flags
features: [
  "auth"
  "api"
  "ui"
  "analytics"
]

# Environment-specific settings
environments: {
  development: {
    debug: true
    logLevel: "debug"
  }
  
  production: {
    debug: false
    logLevel: "error"
  }
}

Schema Validation ​

vz
# Define schema
schema: {
  id: "int(min:1,max:1000)!"
  name: "string(minLength:3,maxLength:50)!"
  email: "string(format:email)!"
  age: "int(min:0,max:150)?"
  status: "enum(active,inactive,pending)!"
  tags: "array?"
  metadata: "object?"
}

# Data that will be validated against schema
id: 123
name: "John Doe"
email: "[email protected]"
age: 30
status: "active"
tags: ["user", "premium"]
metadata: {
  created: "2024-01-01"
  lastLogin: "2024-01-15"
}

Template Strings ​

vz
# Base configuration
api: {
  baseUrl: "https://api.example.com"
  version: "v1"
  timeout: 5000
}

user: {
  id: 123
  name: "Alice"
  role: "admin"
  email: "[email protected]"
}

# Dynamic values using template strings
endpoints: {
  users: "${api.baseUrl}/${api.version}/users"
  userProfile: "${api.baseUrl}/${api.version}/users/${user.id}"
  userEndpoint: "${api.baseUrl}/${api.version}/users/${user.name}"
}

greeting: "Hello, ${user.name}! You are a ${user.role}."
welcomeMessage: "Welcome back, ${user.name}! Your role is ${user.role} and your email is ${user.email}."

Import System ​

vz
# Import shared configurations
import { database, logging, security } from "./config/shared.vz"
import { apiDefaults } from "./config/api.vz"

# Main application configuration
app: {
  name: "MyApp"
  version: "1.0.0"
  
  # Spread imported configurations
  ...database
  ...logging
  ...security
  ...apiDefaults
  
  # Override specific values
  database: {
    ...database
    name: "myapp_production"
  }
  
  api: {
    ...apiDefaults
    timeout: 10000
    retries: 3
  }
}

Multiline Strings with Metadata ​

vz
# Markdown documentation
readme: |markdown
  # MyApp Configuration
  
  This is a comprehensive configuration file for MyApp.
  
  ## Features
  - Authentication
  - API endpoints
  - Database connection
  - Logging
  
  ## Usage
  ```bash
  npm start

JSON configuration ​

config: |json { "database": { "host": "localhost", "port": 5432, "name": "myapp" }, "api": { "baseUrl": "https://api.example.com", "timeout": 5000 } }

Python code ​

script: |python def hello_world(): print("Hello, VZparse!") return True

if name == "main": hello_world()

SQL query ​

query: |sql SELECT u.id, u.name, u.email FROM users u WHERE u.active = true AND u.created_at > '2024-01-01' ORDER BY u.created_at DESC LIMIT 100


## Complex Nested Configuration

```vz
# Complete application configuration
application: {
  name: "E-commerce Platform"
  version: "2.1.0"
  
  # Database configuration
  database: {
    primary: {
      host: "db-primary.example.com"
      port: 5432
      name: "ecommerce"
      ssl: true
      pool: {
        min: 5
        max: 20
        idle: 30000
      }
    }
    
    replica: {
      host: "db-replica.example.com"
      port: 5432
      name: "ecommerce"
      ssl: true
      readonly: true
    }
  }
  
  # API configuration
  api: {
    baseUrl: "https://api.example.com"
    version: "v2"
    timeout: 10000
    retries: 3
    
    endpoints: {
      auth: "/auth"
      users: "/users"
      products: "/products"
      orders: "/orders"
    }
    
    middleware: [
      "cors"
      "rateLimit"
      "auth"
      "logging"
    ]
  }
  
  # Feature flags
  features: {
    auth: {
      enabled: true
      provider: "oauth2"
      providers: ["google", "github", "facebook"]
    }
    
    payments: {
      enabled: true
      providers: ["stripe", "paypal"]
      currencies: ["USD", "EUR", "GBP"]
    }
    
    analytics: {
      enabled: true
      provider: "google-analytics"
      trackingId: "GA-XXXXXXXXX"
    }
  }
  
  # Environment-specific overrides
  environments: {
    development: {
      debug: true
      logLevel: "debug"
      database: {
        primary: {
          host: "localhost"
          port: 5432
        }
      }
    }
    
    staging: {
      debug: false
      logLevel: "info"
      api: {
        baseUrl: "https://staging-api.example.com"
      }
    }
    
    production: {
      debug: false
      logLevel: "error"
      api: {
        baseUrl: "https://api.example.com"
        timeout: 15000
      }
    }
  }
}

Released under the MIT License.