Configuration files are essential for managing infrastructure. This drill teaches you to parse nested JSON configuration data, navigate complex structures, extract attributes, filter by status, and transform data for reporting. You'll learn nested hash navigation, filtering, grouping, and data transformation—essential skills for building DevOps tools and configuration management systems.
JSON.parse(File.read(file)) parses the JSON file
Navigate with data['environments'].each
Access nested values: server['hostname'], server['ip']
Use 'next unless condition' to filter servers
Hash.new { |h, k| h[k] = [] } creates hash with array defaults
array.sort_by! { |item| item[:key] } sorts array in place
hash.keys.sort sorts environment names alphabetically
parse_server_config('servers.json')
SERVER CONFIGURATION REPORT ================================================== Environment: production web-prod-01 - 192.168.1.10:8080 web-prod-02 - 192.168.1.11:8080 Environment: staging db-stage-01 - 10.0.1.20:5432 web-stage-01 - 10.0.1.10:8080 -------------------------------------------------- Total Active Servers: 4 Environments: 2
parse_server_config('servers.json')
puts 'Filtered OK'
SERVER CONFIGURATION REPORT ================================================== Environment: production web-prod-01 - 192.168.1.10:8080 web-prod-02 - 192.168.1.11:8080 Environment: staging db-stage-01 - 10.0.1.20:5432 web-stage-01 - 10.0.1.10:8080 -------------------------------------------------- Total Active Servers: 4 Environments: 2 Filtered OK
parse_server_config('servers.json')
puts 'Sorted OK'
SERVER CONFIGURATION REPORT ================================================== Environment: production web-prod-01 - 192.168.1.10:8080 web-prod-02 - 192.168.1.11:8080 Environment: staging db-stage-01 - 10.0.1.20:5432 web-stage-01 - 10.0.1.10:8080 -------------------------------------------------- Total Active Servers: 4 Environments: 2 Sorted OK
Console output will appear here...
Are you sure?
You're making great progress