Data Navigators
Data Navigators provide a fluent, safe way to navigate and extract data from complex data structures in BoxLang
🎯 Why Use Data Navigators?
Traditional vs Navigator Approach
// ❌ Traditional: Verbose null checking
if ( structKeyExists( config, "database" ) ) {
if ( structKeyExists( config.database, "connection" ) ) {
if ( structKeyExists( config.database.connection, "pool" ) ) {
maxSize = config.database.connection.pool.maxSize ?: 10;
} else {
maxSize = 10;
}
} else {
maxSize = 10;
}
} else {
maxSize = 10;
}
// ✅ With Navigator: Clean and safe
maxSize = dataNavigate( config ).get( "database", "connection", "pool", "maxSize", 10 );🚀 Getting Started
Creating a Data Navigator
Basic Navigation
🧭 Core Navigation Methods
from( ...path ):Navigator
from( ...path ):Navigatorhas( ...path ):boolean
has( ...path ):booleanisEmpty():boolean / isPresent():boolean
isEmpty():boolean / isPresent():boolean🎯 Data Extraction Methods
get( ...keys, [defaultValue] ):Object
get( ...keys, [defaultValue] ):ObjectgetOrThrow( ...keys ):Object
getOrThrow( ...keys ):ObjectTyped Getter Methods
Method
Return Type
Purpose
🎭 Conditional Processing
ifPresent( key, consumer ):Navigator
ifPresent( key, consumer ):NavigatorifPresentOrElse( key, consumer, orElseAction ):Navigator
ifPresentOrElse( key, consumer, orElseAction ):NavigatorPractical Examples
Configuration Management
API Response Processing
Feature Flag Management
Database Configuration
Log Configuration Processing
Error Handling and Validation
Safe Navigation Patterns
Graceful Degradation
Advanced Patterns
Configuration Inheritance
Dynamic Configuration Validation
💡 Best Practices
1. Use Meaningful Defaults
2. Validate Critical Configuration
3. Leverage Dynamic Typing
4. Check Sections Before Processing
5. Use Conditional Methods for Optional Features
6. Structure Navigation Logically
7. Log Configuration Decisions
8. Handle Multiple Data Sources
9. Validate Before Use
10. Keep Navigation Chains Readable
📋 Method Reference Summary
Category
Method
Returns
Description
🎓 Summary
🔗 Related Documentation
Last updated
Was this helpful?
